Generate server code using the OpenAPI Generator based on an OpenAPI specification: OpenAPI Generator can generate code based on an OpenAPI yaml specification.
I am writing OpenAPI specification version 3.0.1/3.0.3 with "Examples in Media Type ie RequestBody and Response". Using OpenAPI generator, it generates code where Annotation for Examples in media type is not generated.
I have tried the following but none has generated Annotation ie @ExampleObject for Examples in RequestBody and Response.
| Source | Server Generator | Integrate swagger to springboot |
|-------------------------|-------------------------|---------------------------------|
| Swagger Editor | Swagger codegen | Springdoc-openapi |
| New Swagger Editor | Swagger codegen | Springdoc-openapi |
| Generate using Cmd | OpenAPI generator 6.1.0 | Springdoc-openapi |
| My Project | OpenAPI generator 4.3.1 | Springfox |
| Blog-Maven project | OpenAPI generator 5.3.0 | Springfox |
Below you can find the OpenAPI Specification I tried:
openapi: 3.0.3
info:
title: Swagger
description: OpenAPI 3.0 specification.
version: 1.0.11
paths:
/test:
put:
summary: Test Examples
description: Test Examples
requestBody:
description: Test Examples
content:
application/json:
schema:
type: string
examples:
example1:
description: Example 1
value: Test string 1
summary: Example-1
example2:
description: Example 2
value: Test string 2
summary: Example-2
example3:
description: Example 3
value: Test string 3
summary: Example-3
required: true
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: string
examples:
example1:
description: Example 1
value: Test response 1
summary: Example-1
example2:
description: Example 2
value: Test response 2
summary: Example-2
example3:
description: Example 3
value: Test response 3
summary: Example-3
'400':
description: Invalid
'404':
description: Not found
'405':
description: Validation exception
Though Examples are displayed in Swagger Editor but I need to generate Annotation for Examples using OpenAPI generator. I don't have an option to manually add @ExampleObject annotation.
Is there any way to generate annotation for Examples using openapi-generator? Please correct me if I misunderstood anything.