Bootstrapping A Project Using OpenAPI Generator
In order to simplify adopting a Contract-First API Development approach, we have created a series of Maven Archetypes which make initializing new projects extremely quick and simple. These archetypes are already published to Maven Central
- Download the OpenAPI specification file for our example project from HERE
- Use Maven to create a new project using the Quarkus Archetype and the downloaded OpenAPI Specificationbash
mvn archetype:generate -B -DarchetypeGroupId=com.redhat.consulting \ -DarchetypeArtifactId=openapi-quarkus-archetype \ -DarchetypeVersion=1.0.5 \ -Dpackage=com.redhat.runtimes \ -DgroupId=com.redhat.runtimes.quarkus \ -DartifactId=quarkus-todo \ -Dversion=0.0.1-SNAPSHOT \ -Dinteractive=false \ -Dquarkus_orm_selection=hibernate-orm \ -Dopenapi_app_contract_uri=/path/to/openapi.yml
TIP
This will create a new Maven project in the current directory under
quarkus-todo
- Make a note of the directory structure in the generated project
$ tree -a . ├── .dockerignore ├── .mvn │ └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── .openapi-generator-ignore ├── pom.xml ├── README.md ├── src │ ├── gen │ │ └── java │ │ └── com │ │ └── redhat │ │ └── runtimes │ │ ├── api │ │ │ ├── TodosApi.java │ │ │ └── UserApi.java │ │ └── models │ │ ├── Todo.java │ │ └── User.java │ └── main │ ├── docker │ │ ├── Dockerfile.jvm │ │ ├── Dockerfile.legacy-jar │ │ ├── Dockerfile.native │ │ └── Dockerfile.native-distroless │ └── resources │ ├── application.properties │ └── openapi.yml ├── target │ └── classes └── templates ├── pojo.mustache └── README.md
src/gen/java
- This is the directory where the OpenAPI Generator Maven Plugin creates the classes from the OpenAPI Specification filesrc/main/docker
- These are Dockerfiles for creating Quarkus containers for deploymentsrc/main/resources
- This is where the application metadata is kepttemplates
- This is where the Maven SCM Plugin clones the custom Quarkus OpenAPI Generator template files.openapi-generator-ignore
- Tells OpenAPI Generator not to generate files/patterns listed inside. This prevents the Maven POM from being overwritten
- Inside of the
pom.xml
, review the plugins and their attachments to the Maven lifecyclebuild-helper-maven-plugin
is attached to thegenerate-sources
phase to ensure that Maven includes thesrc/gen/java
sources in the build pathmaven-scm-plugin
is attached to theinitialize
phase to clone the customer OpenAPI Generator template filesmaven-clean-plugin
is configured to delete the generated sourcesopenapi-generator-maven-plugin
is attached to thegenerate-sources
phase to generate our stubbed JAX-RS Server and Modelsformatter-maven-plugin
is attached to theprocess-sources
phase to format and clean-up the generated codekubernetes-maven-plugin
andopenshift-maven-plugin
from Eclipse JKube - Used to deploy the application to Kubernetes/OpenShift
- Create the subdirectory
src/main/java
as we will be creating our implementations in there starting with the next segement