Skip to content
Advertisement

How to annotate array of objects response in Swagger

I have to debug a REST API Java project that has been developed using Swagger.I’m new to it, so I’m a little bit confused on how to do certain things. For example, here’s one method:

JavaScript

The @ApiResponse for the code 200 is not of type LocationResponse but of type ArrayList<LocationResponse>, as it can return more than one location. What would be the correct syntax for this change? I’ve been reading the documentation at https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X—Annotations#operation-annotations but I couldn’t find an appropriate example…

Thanks!

Advertisement

Answer

Use @ArraySchema instead of plain @Schema to define input or output data for array types.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement