How to use Swagger @ApiResponses annotation in Kotlin?
As stated in the Kotlin Language Reference:
If the value argument [of an Annotation] in Java has an array type, it becomes a vararg parameter in Kotlin
So, to make your example work, you need to put it like so:
@ApiResponses(
ApiResponse(code = 200, message = "..."),
ApiResponse(code = 404, message = "..."),
ApiResponse(code = 500, message = "..."),
ApiResponse(code = 400, message = "..."),
ApiResponse(code = 412, message = "...")
)
For Swagger 3, this is the way to go:
@ApiResponses(value = [
ApiResponse(responseCode = "200", description = "...", content = [
(Content(mediaType = "application/json", array = (
ArraySchema(schema = Schema(implementation = DataModel::class)))))]),
ApiResponse(responseCode = "400", description = "...", content = [Content()]),
ApiResponse(responseCode = "404", description = "...", content = [Content()])]
)
This snippet also includes @Content
, @ArraySchema
and @Schema
annotation examples.