【发布时间】:2020-02-26 16:24:46
【问题描述】:
我正在尝试使用 swagger-maven-plugin 记录我的 api。
当我用@Parameter 注释一个路由参数时,只要它没有用@BeanParam 注释,它就会在openapi 生成的文件中得到很好的记录。
正如swagger核心documentation中所说,
@Parameter 可以用来代替 JAX-RS 参数注释(@PathParam、@QueryParam、@HeaderParam、@FormParam 和 @BeanParam),也可以与它们一起使用。虽然 swagger-core / swagger-jaxrs2 默认扫描这些注解,但 @Parameter 允许为参数定义更多细节。
如何将我的 @BeanParam 参数记录在我的 openapi 文件中?
这是我的pom.xml:
<dependencies>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputFileName>openapi</outputFileName>
<outputPath>target/doc</outputPath>
<outputFormat>YAML</outputFormat>
<resourcePackages>...</resourcePackages>
<readAllResources>false</readAllResources>
</configuration>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>resolve</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
这里是我带注释的 api:
@GET
@Path("/authorize")
@Operation(summary = "Summary", description = "Description")
Response authorize(
// Parameter doesn't show up in generated documentation
@Parameter(
description = "Request",
name = "request",
required = true
)
@BeanParam Oauth2AuthorizationRequest request,
// Parameter shows up correctly in generated documentation
@Parameter(
description = "Session id",
name = "sessionId",
required = true
)
@CookieParam("sessionId") String sessionId
);
生成的文件是:
openapi: 3.0.1
paths:
/auth/oauth2/authorize:
get:
summary: Summary
description: Description
operationId: authorize
parameters:
- name: sessionId
in: cookie
description: Session id
required: true
schema:
type: string
【问题讨论】: