I have a Spring boot Gradle project and I want to get it's OpenAPI spec YAML file.
As I understand the official swagger-core
does not support Spring boot projects, thus I found springdoc-openapi
(https://github.com/springdoc/springdoc-openapi-gradle-plugin).
It seems that in order to get the YAML/JSON files, when running the generateOpenApiDocs
task, the springdoc
library sets up a server with some endpoints (/v3/api-docs) to download the files.
Execution failed for task 'generateOpenApiDocs'. Unable to connect to http://localhost:8080/v3/api-docs waited for 30 seconds
It seems that for some reason it does not set up the server. How can I fix it?
The aim of springdoc-openapi-maven-plugin is to generate json and yaml OpenAPI description during build time. The plugin works during integration-tests phase, and generate the OpenAPI description. The plugin works in conjunction with spring-boot-maven plugin. You can test it during the integration tests phase using the maven command:
Seems like quite a faff given that you need the yaml in order to use the open-api gradle plugin in order to generate api stubs. Pity that they then force everyone to role their own solutions... This happens because sometimes embedded server took sometime to start and it has 30 sec default setting.
The OpenAPI Generator can be used as command line tool or as plugin for build tools like Maven and Gradle. The pom.xml file below shows the integration of the OpenAPI Generator plugin in a Maven project. To generate the server code, you need to add a plugin definition similar to the one below.
Using springdoc-openapi Maven Plugin The springdoc-openapi library provides a Maven plugin springdoc-openapi-maven-plugin for generating OpenAPI descriptions in json and yaml formats. The springdoc-openapi-maven-plugin plugin works with the spring-boot-maven plugin. Maven runs the openapi plugin during the integration-test phase.
If you are deploying REST APIs with spring-boot, you are relying on a servlet container.
The necessry metadata for the OpenAPI spec are only available by spring framework on runtime, which explains the choice of generation at runtime.
You can define any embeded servlet container, during your integration tests to generate the OpenAPI Spec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With