我需要调试一个使用Swagger开发的REST API Java项目。由于我是新手,所以我有点困惑如何做某些事情。例如,这里有一个方法:
@GET
@Path("/location/name")
@Produces({MediaType.APPLICATION_JSON})
@Operation(
summary = "Get location information",
tags = {"Information"},
responses = {
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = LocationResponse.class)), description = "Get location information"),
@ApiResponse(responseCode = "500", description = "Error: Internal Server Error")
}
)
public Response searchLocationByName(
@Parameter(description = "Location name", required = true) @DefaultValue("Barcelona") @QueryParam("name") String locationName
) { /* METHOD CODE */ }
@ApiResponse
对于状态码 200 不是 LocationResponse
类型而是 ArrayList<LocationResponse>
类型,因为它可以返回多个位置信息。这种更改的正确语法应该是什么?我一直在阅读https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#operation-annotations 上的文档,但没有找到合适的例子......谢谢!
@ArraySchema
注释,但是我误解了文档,认为它不是我所需要的...这是我的错误。现在使用这个注释:@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = LocationResponse.class))), description = "Get location information")
,它可以工作了。谢谢! - Fel