question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Java] Can't genereate code with OpenApi 3 Annotations (Springboot)

See original GitHub issue
Description

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
  1. configure the plugin to use a simple example yaml
  2. Do a maven clean install
  3. 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:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MaSvencommented, Jan 21, 2021

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.

0reactions
anban02commented, Jan 22, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documenting a Spring REST API Using OpenAPI 3.0 - Baeldung
Generate Spring Boot REST Client with Swagger. Learn how you can generate a Spring Boot REST client using Swagger Code generator.
Read more >
java - How to Integrate Open API 3 with Spring project (not ...
The ui load for spring-mvc (5.3.1) using springdoc-openapi-ui 1.5.2 looks more simple: build.gradle (gradle version 6.5)
Read more >
Generate Server Code Using OpenAPI Generator
In this blog, you will learn how to generate server code using the OpenAPI Generator based on an OpenAPI specification. The code will...
Read more >
Using the OpenAPI Generator for Spring Boot - mimacom blog
We go for generating the code directly in the implementation project. The OpenAPI Generator can be used as command line tool or as...
Read more >
Documentation for the spring Generator
helpTxt, Generates a Java SpringBoot Server application using the SpringDoc ... none: Do not annotate Model and Api with complementary ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found