亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java中Swagger core v3的實現

java中Swagger core v3的實現

搖曳的薔薇 2023-01-05 17:24:40
我正在編寫一些 API,并且我想在編寫代碼時集成文檔,因此我發現 Swagger 是實現此目的的好方法。我使用了 Swagger 核心 v3 符號,所以我的課程類似于:@RestController@RequestMapping("/api/v1/bundles")@OpenAPIDefinition(        info = @Info(                title = "Lifecycle Management RESTful API.",                version = "1",                description = "TODO",                license = @License(name = "Apache 2.0", url = "xxx"),                contact = @Contact(url = "xxx", name = "xx", email = "[email protected]")        ))public class RestBundle {    @GetMapping(value = "/{nodeId}",            produces = MediaType.APPLICATION_JSON_VALUE)    @ResponseStatus(HttpStatus.OK)    @ResponseBody    @Operation(summary = "Get all bundles",            description = "Get all available bundles status from a specific node")    public Something(..)  {        //Something ...    }}我創建了一個配置類:@Configuration@EnableSwagger2public class SwaggerConfig {    @Bean    public Docket api() {        return new Docket(DocumentationType.SWAGGER_2)                .select()                .apis(RequestHandlerSelectors.any())                .paths(PathSelectors.any())                .build()                .apiInfo(apiInfo());    }    ApiInfo apiInfo() {        return new ApiInfoBuilder()                .title("ANF Orchestrator")                .description("REST API for ANF Orchestrator")                .license("Apache 2.0")                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")                .termsOfServiceUrl("")                .version("1.0.0")                .contact(new Contact("Amine","xxx", "[email protected]"))                .build();    }}我想啟用 Swagger 的 UI 來獲取文檔,但是當我輸入時:.../swagger-ui.html我得到:無法呈現此定義提供的定義未指定有效的版本字段。請指明有效的 Swagger 或 OpenAPI 版本字段。支持的版本字段有 swagger: "2.0" 和匹配 openapi: 3.0.n 的字段(例如 openapi: 3.0.0)。
查看完整描述

2 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

嘗試使用 WebMvcConfigurationSupport 擴展您的SwaggerConfig類,并使用如下實現覆蓋其名為addResourceHandlers的方法:


@Override

protected void addResourceHandlers(ResourceHandlerRegistry registry) {

    registry.addResourceHandler("swagger-ui.html")

            .addResourceLocations("classpath:/META-INF/resources/");

    registry.addResourceHandler("/webjars/**")

            .addResourceLocations("classpath:/META-INF/resources/webjars/");

}


查看完整回答
反對 回復 2023-01-05
?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

在課堂之上,您能否嘗試刪除此注釋,因為 SwaggerConfig 已經包含 Docket 信息。


  @OpenAPIDefinition(


            info = @Info(

                    title = "Lifecycle Management RESTful API.",

                    version = "1",

                    description = "TODO",

                    license = @License(name = "Apache 2.0", url = "xxx"),

                    contact = @Contact(url = "xxx", name = "xx", email = "[email protected]")

            ))


查看完整回答
反對 回復 2023-01-05
  • 2 回答
  • 0 關注
  • 399 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號