Java @使用@Parameter注释时未记录BeanParam
我正试图使用Java @使用@Parameter注释时未记录BeanParam,java,swagger,jax-rs,Java,Swagger,Jax Rs,我正试图使用swagger-maven插件记录我的api 当我用@Parameter注释route param时,只要它没有用@BeanParam注释,它就会在openapi生成的文件中得到很好的记录 正如《昂首阔步》中所述 @参数可以代替JAX-RS参数注释(@PathParam、@QueryParam、@HeaderParam、@FormParam和@BeanParam)或与之一起使用。默认情况下,swagger-core/swagger-jaxrs2扫描这些注释时,@参数允许为参数定义更多
swagger-maven插件
记录我的api
当我用@Parameter
注释route param时,只要它没有用@BeanParam
注释,它就会在openapi生成的文件中得到很好的记录
正如《昂首阔步》中所述
@参数可以代替JAX-RS参数注释(@PathParam、@QueryParam、@HeaderParam、@FormParam和@BeanParam)或与之一起使用。默认情况下,swagger-core/swagger-jaxrs2扫描这些注释时,@参数允许为参数定义更多细节
如何获取openapi文件中记录的@BeanParam
参数
这是我的pom.xml
:
io.swagger.core.v3
斯威格-jaxrs2
2.1.1
io.swagger.core.v3
大摇大摆的maven插件
2.1.1
openapi
目标/单据
亚马尔
...
假的
产生资源
决定
这里是我的带注释的api:
@GET
@路径(“/authorize”)
@操作(summary=“summary”,description=“description”)
响应授权(
//参数未显示在生成的文档中
@参数(
description=“请求”,
name=“请求”,
必需=真
)
@BeanParam Oauth2AuthorizationRequest请求,
//参数在生成的文档中正确显示
@参数(
description=“会话id”,
name=“sessionId”,
必需=真
)
@CookieParam(“sessionId”)字符串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
。注释必须放在类注释@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
);
经过一些试验后,我设法在openapi文件中记录了我的
@BeanParam
。注释必须放在类注释@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
);
它能倒过来吗?有一个openapi yml文件生成一个带有beanparam的接口吗。我没试过,但看起来像你要找的。我知道。我只是没有找到一种方法来生成一个带有@beanparam的接口,而不是单独的接口parameters@Baboo_您是否理解为什么只有在BeanParm的情况下,我们才需要使用swagger注释来注释对象的(Oauth2AuthorizationRequest)参数?我的意思是,如果它不是BeanParam,那么swagger将自动读取验证注释,因此您可以使用NotNull注释而不是您使用的参数(requires=true)。我不确定为什么。BeanParam是一组参数,我认为swagger与简单参数有区别。如果你知道为什么我很想知道会不会是另一种情况?有一个openapi yml文件生成一个带有beanparam的接口吗。我没试过,但看起来像你要找的。我知道。我只是没有找到一种方法来生成一个带有@beanparam的接口,而不是单独的接口parameters@Baboo_您是否理解为什么只有在BeanParm的情况下,我们才需要使用swagger注释来注释对象的(Oauth2AuthorizationRequest)参数?我的意思是,如果它不是BeanParam,那么swagger将自动读取验证注释,因此您可以使用NotNull注释而不是您使用的参数(requires=true)。我不确定为什么。BeanParam是一组参数,我认为swagger与简单参数有区别。如果你知道我为什么想知道