温馨提示:本文翻译自stackoverflow.com,查看原文请点击:java - How to annotate array of objects response in Swagger
java swagger

java - 如何在Swagger中注释对象数组响应

发布于 2020-03-29 22:00:48

我必须调试一个使用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上阅读文档,但找不到合适的示例。 。

谢谢!

查看更多

提问者
Fel
被浏览
155
y_ug 2020-01-31 18:55