We have used lately springdoc-openapi java library. It helps automating the generation of API documentation using spring boot projects.
It automatically deploys swagger-ui to a spring-boot application
Documentation will be available in HTML format, using the official [swagger-ui jars]:
The Swagger UI page should then be available at http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url for json format: http://server:port/context-path/v3/api-docs
- server: The server name or IP
- port: The server port
- context-path: The context path of the application
Documentation can be available in yaml format as well, on the following path: /v3/api-docs.yaml. (to convert into yaml)
Add the library to the list of your project dependencies (No additional configuration is needed)
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.3</version>
</dependency>
Answer from user11878890 on Stack OverflowWe have used lately springdoc-openapi java library. It helps automating the generation of API documentation using spring boot projects.
It automatically deploys swagger-ui to a spring-boot application
Documentation will be available in HTML format, using the official [swagger-ui jars]:
The Swagger UI page should then be available at http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url for json format: http://server:port/context-path/v3/api-docs
- server: The server name or IP
- port: The server port
- context-path: The context path of the application
Documentation can be available in yaml format as well, on the following path: /v3/api-docs.yaml. (to convert into yaml)
Add the library to the list of your project dependencies (No additional configuration is needed)
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.3</version>
</dependency>
I was missing some library for this for longer time. Finally, decided to implement my own generator https://github.com/jrcodeza/spring-openapi maybe you can check it out too. It's based on reflection and supports javax and spring annotations. It also generates inheritance model (with discriminators) based on Jackson annotations. Besides you can define your own interceptors if you want to alter generation process (e.g. when you have your own annotations and need to adjust generated sections of schema). You can use it in runtime mode or as a maven plugin. There is also OpenAPI3 to java client generator, which generates the model. Again it generates also Javax annotations and Jackson annotations for correct inheritance.
Videos
The openapi-generator has several different generators which can read in a yaml file and output code in your preferred language. Some of the generators include java, html, html2, spring, and javascript. The comprehensive list of generators can be found here.
The openapi-generator can be ran via CLI, as well as its maven and gradle plugins.
Since you already have a valid openapi specification file, I'd recommend using the generator to generate a spring server using the spring-boot library and set the documentationProvider to springdoc. This will generate the spring java classes with appropriate springdoc annotations as well as the swagger-ui.html endpoint you are requesting.
Including Springdoc v2 dependency into pom.xml generated a Swagger UI page based on the component-scanned controllers accessible at http://localhost:8080/swagger-ui/index.html and its OpenAPI description at http://localhost:8080/v3/api-docs.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.4</version>
</dependency>
Note I use Spring Boot 3.0.2