1

For my API I'm making a meta annotation for handling Pagable parameters and for it I need to annotate a list of strings as a parameter that will show up in Swagger UI.

import io.swagger.v3.oas.annotations.Parameter;

@Parameter(name = "sort", in = ParameterIn.QUERY, schema = @Schema(implementation = String.class, type = "query"))
public @interface PageableQueryParameters {}

In order to sort by multiple criteria in Spring's Pageable the sort parameter needs to be provided as a list of strings. Unfortunately I don't know how to declare the sort parameter as a list.

How can I document a list of strings using Swagger's OpenAPI 3 annotations?

2 Answers 2

1

If I'm understanding you correctly, to indicate that the "sort" parameter is a list, you need to use the parameters array like the following:

schema = @Schema(implementation = String.class, type = "query"

should be changed to

array = @ArraySchema(implementation = String.class)

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately Swagger UI still shows sort as a single parameter.
parameters = { @Parameter(in = ParameterIn.QUERY, required = false, name = "sort", description = "Sorting criteria in the format: property(,asc|desc). Default sort order is ascending. Multiple sort criteria are supported.", example = "sort=customerId,desc&sort=id,desc", array = @ArraySchema( schema = @Schema(type = "string"))) }
1

You should use this:

array = @ArraySchema(schema = @Schema(implementation = String.class))

1 Comment

in 2025 this should be the accepted answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.