Skip to content

Instantly share code, notes, and snippets.

@rkbalgi
Last active January 25, 2019 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkbalgi/0cc90adfecb25b38ccd192081dd1a3ce to your computer and use it in GitHub Desktop.
Save rkbalgi/0cc90adfecb25b38ccd192081dd1a3ce to your computer and use it in GitHub Desktop.
Generate and build swagger API client using maven
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<configuration>
<apiSources>
<apiSource>
<springmvc>true</springmvc>
<locations>
<location>com.example.resources.DemoResource</location>
</locations>
<info>
<title>Demonstration</title>
<version>v1.0</version>
<description>This is a demo</description>
</info>
<schemes>
<scheme>https</scheme>
</schemes>
<host>www.example.com</host>
<basePath>/demo_app</basePath>
<outputPath>${basedir}/target/generated</outputPath>
<outputFormats>yaml</outputFormats>
<swaggerDirectory>${basedir}/target/swagger</swaggerDirectory>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<modelPackage>com.example.model</modelPackage>
<apiPackage>com.example.api</apiPackage>
<invokerPackage>com.example.invoker</invokerPackage>
<inputSpec>${project.basedir}/target/swagger/swagger.yaml</inputSpec>
<language>java</language>
<configOptions>
<groupId>com.example</groupId>
<artifactId>example-client</artifactId>
<version>${project.version}</version>
<sourceFolder>src/main/java</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>
<argument>install</argument>
<argument>-f</argument>
<argument>target/generated-sources/swagger/pom.xml</argument>
</arguments>
<executable>mvn</executable>
</configuration>
</plugin>
@rkbalgi
Copy link
Author

rkbalgi commented Jan 25, 2019

The POM snippet allows building of swagger definition file (swagger.yaml), then using it to generate Java sources for the API client and then build the generated sources and push it to a repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment