如何在 Swagger 中注释对象响应数组
我必须调试一个使用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 */ }
代码 200 不是类型,而是类型,因为它可以返回多个位置。此更改的正确语法是什么?我一直在阅读 https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#operation-annotations 的文档,但我找不到合适的示例...@ApiResponse
LocationResponse
ArrayList<LocationResponse>
谢谢!