使用@Parameter 注释时未记录@BeanParam
@BeanParam not documented when annotated with @Parameter
我正在尝试使用 swagger-maven-plugin
.
记录我的 api
当我使用 @Parameter
注释路由参数时,只要未使用 @BeanParam
.
注释,打开 api 生成的文件中就有详细记录
如 swagger 核心所述 documentation,
The @Parameter can be used in place of or together with the JAX-RS parameter annotations (@PathParam, @QueryParam, @HeaderParam, @FormParam and @BeanParam). While swagger-core / swagger-jaxrs2 scan these annotations by default, the @Parameter allows to define more details for the parameter.
如何将我的 @BeanParam
参数记录在我的打开api 文件中?
这是我的 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
经过一些试验后,我设法在 openapi 文件中记录了我的 @BeanParam
。注释必须放在 class 注释的 @BeanParam
中,如下所示:
public class Oauth2AuthorizationRequest {
// Use the @Parameter annotation to document the attribute.
@HeaderParam("Authorization")
@Parameter(description = "Authorization header")
String authorization;
// If the attribute is a @FormParam, use the @Schema annotation.
@FormParam("client_id")
@Schema(description = "The id of the client")
String client_id;
// If the attribute is a @FormParam and is required,
// use the @Schema annotation for the description
// and the @Parameter one to set it as required.
@FormParam("grant_type")
@Schema(description = "Should be either \"credentials\" or \"password\"")
@Parameter(required = true)
String grant_type;
}
端点被简化为:
@GET
@Path("/authorize")
@Operation(summary = "Summary", description = "Description")
Response authorize(
// No more annotation on the @BeanParam
@BeanParam Oauth2AuthorizationRequest request,
@Parameter(
description = "Session id",
name = "sessionId",
required = true
)
@CookieParam("sessionId") String sessionId
);
我正在尝试使用 swagger-maven-plugin
.
当我使用 @Parameter
注释路由参数时,只要未使用 @BeanParam
.
如 swagger 核心所述 documentation,
The @Parameter can be used in place of or together with the JAX-RS parameter annotations (@PathParam, @QueryParam, @HeaderParam, @FormParam and @BeanParam). While swagger-core / swagger-jaxrs2 scan these annotations by default, the @Parameter allows to define more details for the parameter.
如何将我的 @BeanParam
参数记录在我的打开api 文件中?
这是我的 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
经过一些试验后,我设法在 openapi 文件中记录了我的 @BeanParam
。注释必须放在 class 注释的 @BeanParam
中,如下所示:
public class Oauth2AuthorizationRequest {
// Use the @Parameter annotation to document the attribute.
@HeaderParam("Authorization")
@Parameter(description = "Authorization header")
String authorization;
// If the attribute is a @FormParam, use the @Schema annotation.
@FormParam("client_id")
@Schema(description = "The id of the client")
String client_id;
// If the attribute is a @FormParam and is required,
// use the @Schema annotation for the description
// and the @Parameter one to set it as required.
@FormParam("grant_type")
@Schema(description = "Should be either \"credentials\" or \"password\"")
@Parameter(required = true)
String grant_type;
}
端点被简化为:
@GET
@Path("/authorize")
@Operation(summary = "Summary", description = "Description")
Response authorize(
// No more annotation on the @BeanParam
@BeanParam Oauth2AuthorizationRequest request,
@Parameter(
description = "Session id",
name = "sessionId",
required = true
)
@CookieParam("sessionId") String sessionId
);