我正在使用Quarkus开发一组JAX-RS服务。我还使用OpenAPI/Swagger-UI注释来注释它们,以便轻松生成API文档。我可以像这样注释我的GET服务...
@Path("/{communityIdentifier}")
@GET
@Operation(summary = "Get community details", description = "Get detailed information about a community")
@APIResponses({
@APIResponse(responseCode = "200", description = "The community details", content = @Content(schema = @Schema(ref = "community"))),
@APIResponse(name = "401", responseCode = "401", description = "Authentication required"),
@APIResponse(name = "403", responseCode = "403", description = "Permission denied - you do not have access to access this resource", content = @Content(schema = @Schema(ref = "baseError"))),
@APIResponse(name = "404", responseCode = "404", description = "Resource not found", content = @Content(schema = @Schema(ref = "baseError"))),
@APIResponse(name = "500", responseCode = "500", description = "Internal service error", content = @Content(schema = @Schema(ref = "baseError"))) })
@Timed(name = "getCommunityTimer")
@Counted(name = "getCommunityCount")
public Response getCommunity(
@PathParam("securityRealm") @Parameter(name = "securityRealm", description = "The security realm name", required = true) String securityRealmName,
@PathParam("communityIdentifier") @Parameter(name = "communityIdentifier", description = "The community identifier", required = true) String communityIdentifier) {
// Stuff
}当我访问我的Swagger UI端点时,我看到了这个服务的记录良好的条目,包括关于securityRealm和communityIdentifier参数的信息。现在,我正在尝试以类似的方式创建POST和PUT方法,但遇到了一个问题。
因为我的PUT/POST请求包含许多表单参数,所以我将它们封装到一个对象中,并用@BeanParam注释该方法。我的表单对象如下所示:
public class CommunityRequestForm extends AbstractRequestForm {
private static final long serialVersionUID = 6007695645505404656L;
@FormParam("description")
private String description = null;
@FormParam("name")
private String name = null;
public String getDescription() {
return description;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public void setName(String name) {
this.name = name;
}
}我的POST方法如下所示:
@Path("/")
@POST
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
@Operation(summary = "Create a community", description = "Creates a new community within a security realm")
@APIResponses({
@APIResponse(responseCode = "201", description = "The community details", content = @Content(schema = @Schema(ref = "community"))),
@APIResponse(name = "401", responseCode = "401", description = "Authentication required"),
@APIResponse(name = "403", responseCode = "403", description = "Permission denied - you do not have access to access this resource", content = @Content(schema = @Schema(ref = "baseError"))),
@APIResponse(name = "404", responseCode = "404", description = "Resource not found", content = @Content(schema = @Schema(ref = "baseError"))),
@APIResponse(name = "500", responseCode = "500", description = "Internal service error", content = @Content(schema = @Schema(ref = "baseError"))) })
public Response createCommunity(
@PathParam("securityRealm") @Parameter(name = "securityRealm", description = "The security realm name", required = true) String securityRealmName,
@BeanParam CommunityRequestForm communityForm) {
// Stuff
}到现在为止还好。但是,我还不能弄清楚如何注释name和description参数,以便使用OpenAPI/Swagger-UI对它们进行记录。我尝试将参数注释和定义更改为如下所示:
@FormParam("description")
@Parameter(name = "description", required = true, style = ParameterStyle.FORM)
private String description = null;什么都没做。我尝试将我的方法签名更改为如下所示:
public Response createCommunity(
@PathParam("securityRealm") @Parameter(name = "securityRealm", description = "The security realm name", required = true) String securityRealmName,
@Parameter(style = ParameterStyle.FORM) @BeanParam CommunityRequestForm communityForm)还是一无所获。我的问题是,有没有一种方法可以让OpenAPI/Swagger-UI注释很好地发挥作用,并记录一个带@BeanParam注释的对象?或者根本不支持这种方法?
发布于 2019-09-19 05:46:24
我知道他们在SmallRye OpenAPI 1.1.5中通过PR:https://github.com/smallrye/smallrye-open-api/pull/138改进了这一切。
Quarkus 0.22.0仍使用1.1.3。我们已经在主版本中更新到了1.1.8,所以即将发布的0.23.0版本也会有更新。
您可以尝试使用Quarkus主分支(只需使用mvn clean install -DskipTests -DskipITs构建它,然后将版本更改为999-SNAPSHOT)。希望情况会好起来。
https://stackoverflow.com/questions/57998793
复制相似问题