I am trying to add swagger documentation to my project. I need to add multiple examples for the @Parameter in @RequestBody for the Sample.class, The following piece of code is how its mentioned to be written in the docs.
@PostMapping("/")
public Sample createSample(@Parameter(description="Sample description", examples = {
@ExampleObject(name="foo", description = "na",summary = "na",value = "{\n" +
" \"id\": 10,\n" +
" \"name\": \"ashith\",\n" +
" \"description\": \"none\"\n" +
"}"),
@ExampleObject(name="bar",description = "na",summary = "na",value = "{\n" +
" \"id\": 20,\n" +
" \"name\": \"Akshatha\",\n" +
" \"description\": \"ok\"\n" +
"}")
}
)
@RequestBody Sample sample) {
The yaml output being generated is the following:
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: 'http://localhost:8080/'
description: Generated server url
paths:
/api/another/:
post:
tags:
- another-controller
operationId: createSample
requestBody:
description: Sample description
content:
application/json:
schema:
$ref: '#/components/schemas/Sample'
required: true
responses:
'200':
description: default response
content:
'*/*':
schema:
$ref: '#/components/schemas/Sample'
'400':
description: default response
content:
'*/*':
schema:
type: string
'404':
description: default response
content:
'*/*':
schema:
type: string
This seems to be missing the examples that should have been added as per the code