https://www.dariawan.com/tutorials/spring/documenting-spring-boot-rest-api-springdoc-openapi-3/
尝试遵循这些
我如何处理类似的注释
@ApiModel(value = "Response container")
@ApiModelProperty(value = "Iventory response", required = true)
答案 0 :(得分:21)
springdoc-openapi-ui
依赖项。 <dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>@springdoc.version@</version>
</dependency>
用不可靠的3个注释替换不可靠的2个注释(它已经包含在springdoc-openapi-ui
依赖项中)。
摇摇欲坠的3个注释的软件包为io.swagger.v3.oas.annotations
。
@ApiParam
-> @Parameter
@ApiOperation
-> @Operation
@Api
-> @Tag
@ApiImplicitParams
-> @Parameters
@ApiImplicitParam
-> @Parameter
@ApiIgnore
-> @Parameter(hidden = true)
或@Operation(hidden = true)
或@Hidden
@ApiModel
-> @Schema
@ApiModelProperty
-> @Schema
此步骤是可选的:仅当您有多个 Docket
个bean时,才能将它们替换为GroupedOpenApi
个bean。
之前:
@Bean
public Docket publicApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("org.github.springshop.web.public"))
.paths(PathSelectors.regex("/public.*"))
.build()
.groupName("springshop-public")
.apiInfo(apiInfo());
}
@Bean
public Docket adminApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("org.github.springshop.web.admin"))
.paths(PathSelectors.regex("/admin.*"))
.build()
.groupName("springshop-admin")
.apiInfo(apiInfo());
}
现在:
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.setGroup("springshop-public")
.pathsToMatch("/public/**")
.build();
}
@Bean
public GroupedOpenApi adminApi() {
return GroupedOpenApi.builder()
.setGroup("springshop-admin")
.pathsToMatch("/admin/**")
.build();
}
如果只有个 Docket
,请删除它,然后将属性添加到您的application.properties
:
springdoc.packagesToScan=package1, package2
springdoc.pathsToMatch=/v1, /api/balance/**
添加OpenAPI
类型的bean。参见示例:
@Bean
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info().title("SpringShop API")
.description("Spring shop sample application")
.version("v0.0.1")
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
.externalDocs(new ExternalDocumentation()
.description("SpringShop Wiki Documentation")
.url("https://springshop.wiki.github.org/docs"));
}
如果swagger-ui是在代理后面提供的:
自定义Swagger UI
从文档中隐藏操作或控制器
答案 1 :(得分:4)
您可以将Swagger2注释更新为Swagger3(受springdoc支持)。
带有有用的正则表达式的文章: https://www.david-merrick.com/2017/11/15/useful-regexes-for-transitioning-swagger-2-0-to-3-0-annotations/
@ApiModel
和@ApiModelProperty
都需要替换为@Schema
(io.swagger.v3.oas.annotations.media.Schema
)