[Java] Can't genereate code with OpenApi 3 Annotations (Springboot)
See original GitHub issueDescription
Hello, I am using the generator in a java project (Springboot Application) and want it to generate the code with Annotations for openapi 3.0 instead of swagger. After searching for a longer period of time I could not find any information on how tow do that. Is there a setting that i can change to achieve this or do i need to use a different version / product branch?
As I use the generated code to generate my openapi 3.0 documentation I struggle with missing information in the endpoint documentation, such as the different responses and codes that i have defined.
If there is anything that is not clear or that i have done wrong in this issue, please let me know. It is the first issue I made and as such might not be too good.
openapi-generator version
Using version 5.0.0 of the “openapi-generator-maven-plugin”
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: 1.0.0
title: ABC
description: Miscellaneous endpoints for all apps and clients
servers:
- url: http://localhost:3002/app-gateway-api-doc
description: local dev server
paths:
/knock-knock:
get:
description: Check connection and get the name of the server
operationId: knockKnock
parameters:
- $ref: "#/components/parameters/language"
responses:
"200":
description: knock knock response
content:
application/json:
schema:
$ref: "#/components/schemas/KnockKnockResponse"
"400":
description: "User not authorized"
default:
description: Error
content:
application/json:
schema:
$ref: "#/components/schemas/RestError"
components:
parameters:
language:
name: language
description: 2-letter language code
in: query
schema:
$ref: "#/components/schemas/Language"
schemas:
KnockKnockResponse:
type: object
description: A simple response for clients to check, if the server is online, test,
if the auth token is still valid.
required:
- whoIsThere
properties:
whoIsThere:
type: string
description: Name of server
example: Springboot Example, Server xy, v1.0.6
RestError:
type: object
description: Default API error model
required:
- type
- message
properties:
message:
type: string
description: The error message
example: There is no resource for path /404
errorType:
type: string
description: Type of error
example: UnknownResourceError
additionalProperties:
type: array
description: Key/value array to transport additional error information
items:
$ref: "#/components/schemas/RestErrorAdditionalProperty"
RestErrorAdditionalProperty:
type: object
description: Key/value object to transport additional error information
required:
- key
- value
properties:
key:
type: string
example: foo
value:
type: string
example: bar
Language:
type: string
description: 2-letter language code
default: de
enum: [de, fr, it, en]
Command line used for generation
Using Maven to build the project. mvn clean install
Steps to reproduce
- configure the plugin to use a simple example yaml
- Do a maven clean install
- look at the generated Api File and check if the methods have openapi 3.0 annotations or just swagger
Example of my plugin configuration for this.
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.3</version>
<executions>
<execution>
<id>spring-boot-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skip>false</skip>
<inputSpec>${project.basedir}/src/main/resources/openapi/knock.yaml</inputSpec>
<generatorName>spring</generatorName>
<configOptions>
<dateLibrary>joda</dateLibrary>
<interfaceOnly>true</interfaceOnly>
</configOptions>
<library>spring-boot</library>
<apiPackage>ch.company.project.knock.api</apiPackage>
<modelPackage>ch.company.project.knock.api.model</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
Related issues/PRs
Suggest a fix/enhancement
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
For your interest I asked if I can rebuild the spring generation in #8435 so we can generate the code with springdoc instead of springfox. This is also a breaking change, so I think it is only fair to wait for a response there.
@MaSven Thank you for your reply. As I understood it from what you have written: “The current version cannot do that right now” I’ll keep an eye on the issue you mentioned.