I am developing a service-based application for which I am adding openapi based annotations such as @RequestBody, @Parameter, @Schema within the @Schema I have an example field for which I can provide the example template in String format.
I have provided the example JSON string but the JSON content is huge so I would like to add it from the file present in my resources folder. But I am currently unable to load it. Can someone please let me know how can I add the example content from the file rather than String?
I tried looking and found that there is a field externalValue but I am unable to understand how to make it work. Following is the link to the documentation.
Following is the code I have which is working perfectly fine:
@Path("/generate")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RequestBody(description = "InputTemplate body",
content = @Content(schema = @Schema(implementation = InputTemplate.class, example = "{\n" +
" \"names\":[\n" +
" \"Batman\",\n" +
" \"Superman\",\n" +
" \"Ironman\"\n" +
" ],\n" +
" \"jobs\":[\n" +
" \"Fighting\",\n" +
" \"Fyling\",\n" +
" \"Teching\"\n" +
" ]\n" +
"}")))
public Multi<String> generate(final Map<String, Object> input) throws CustomException {
}
I would like to replace the JSON contents present example with the contents from the external file which is present in my resources folder.
After trying many things I got to know that I need to use @ExampleObject but if I add the respective annotations and try to open my Swagger UI then I am not getting the contents of the file that I have added. Rather it provides me with the data from InputTemplate.class.
Following is the modified code:
@RequestBody(description = "InputTemplate body",
content = @Content(schema = @Schema(implementation = InputTemplate.class), examples = {
@ExampleObject(name = "Example-1",
description = "Example-1 for InputTemplate.",
ref = "#/resources/Example1.json"), externalValue = "#/resources/Example2.json"
@ExampleObject(name = "Example-2",
description = "Example-2 for InputTemplate.",
ref = "#/resources/Example1.json") //externalValue = "#/resources/Example1.json"
}))
I tried to look into a similar question but the provided response does not work for me: