我必须调试一个使用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
,但类型的ArraList<LocationResponse>
,因为它可以返回多个位置。此更改的正确语法是什么?我一直在https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#operation-annotations上阅读文档,但找不到合适的示例。 。
谢谢!
使用@ArraySchema
而不是纯@Schema
以限定用于数组类型的输入或输出数据。
我看到了
@ArraySchema
注解,但是我误解了文档,我认为那不是我所需要的...我的错。现在,它正在使用此注释:@ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = LocationResponse.class))), description = "Get location information"),
。谢谢!