There are no good examples out on the web of how to get the following output using the springdocs-openapi library (1.5.7). I'm looking to get the following output:
[
"A", "B", "C"
]
This is the code based on what examples are provided.
@Operation(summary = "")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = {@Content(mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = String.class)),
examples = {@ExampleObject("A"), @ExampleObject("B"), @ExampleObject("C")}
)})
This results in the following output
[
"string"
]
How is the output listed above ["A","B","C"] possible through springdocs-openapi library?
You are using the
@ExampleObject
incorrectly. Thevalue
attribute (also the default attribute if you don't specify anything) takes a JSON serialized object of the example payload.Thus to get
["A", "B"]
, you don't need multiple@ExampleObject
, rather you need one annotation for one example.Thus updating the code as shown below should be helpful
Shown below is the output of the above code
To specify multiple examples, there should be multiple example objects as shown below
NOTE: The
name
attribute of@ExampleObject
is used to identify the example internally in the specification file.And the output is as shown below