Demo project to generate server stub from OpenAPI Spec.
More details are available at - openapi-generator github and openapi-generator tech.
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/open-api-doc/open-api.json
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.openapi.generator.demo.api</apiPackage>
<modelPackage>com.openapi.generator.demo.model</modelPackage>
<invokerPackage>com.openapi.generator.demo.invoker</invokerPackage>
<addCompileSourceRoot>false</addCompileSourceRoot>
<output>${project.basedir}</output>
<generateApis>true</generateApis>
<generateApiTests>true</generateApiTests>
<generateModelTests>true</generateModelTests>
<skipIfSpecIsUnchanged>false</skipIfSpecIsUnchanged>
<skipOverwrite>true</skipOverwrite>
<supportingFilesToGenerate>
ApiUtil.java
</supportingFilesToGenerate>
<configOptions>
<delegatePattern>true</delegatePattern>
<documentationProvider>springdoc</documentationProvider>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
- Generate API documentation. You can use Swagger editor to generate API doc.
- Upload generated API documentation in project base directory.
- Add
openapi-generator-maven-plugin
in pom.xml. (Refer above mentioned pom.xml for plugin configurations) - execute maven goal
mvn clean install
. - Model, controller, util, API classes will be generated at the location specified in
<output> ... </output>
. - If the output location is not specified, by default classes are generated at
${project.build.directory}/generated-sources/openapi
. - You may have to add some other dependencies to avoid compilation error.