Ask Your Question
3

How can Swagger V3 use Schema Annotation to transform a List of Long to look like a List of String?

asked 2022-01-14 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-11 09:00:00 +0000

ladyg gravatar image

To transform a List of Long in Swagger V3 to look like a List of String, you can use the @Schema annotation with the type parameter set to string. Here's an example:

import io.swagger.v3.oas.annotations.media.Schema;

public class ExampleModel {

  @Schema(type = "array", items = @Schema(type = "string"))
  private List<Long> numbers;

  // getters and setters

}

In this example, the @Schema annotation is applied to the numbers field of the ExampleModel class. The type parameter is set to "array", indicating that this field is an array or list. The items parameter is also set to a nested @Schema annotation with the type parameter set to "string", which indicates that each item in this array should be represented as a string.

This will cause the Swagger documentation to display the numbers field as an array of strings, even though it is actually a list of longs in the code.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-14 11:00:00 +0000

Seen: 14 times

Last updated: Feb 11 '22