Code generator to produce java client and server mappings from Swagger / OpenAPI REST API definition.
MIT License
This project provides a set of tools to generate java code from API definition.
To get list of arguments:
java -jar swagger-tools-cli.jar
To generate models and client code:
java -jar swagger-tools-cli.jar \
--source.location=swagger.yaml \
--target.model.location=./generated \
--target.model.model-package=com.example.model \
--target.client.location=./generated \
--target.client.model-package=com.example.model \
--target.client.client-package=com.example.client \
<build>
<plugins>
<plugin>
<groupId>com.github.agliznetsov.swagger-tools</groupId>
<artifactId>swagger-tools-maven-plugin</artifactId>
<version>0.2.0</version>
<executions>
<execution>
<id>petstore</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sources>
<param>${project.basedir}/src/main/resources/petstore.yaml</param>
</sources>
<options>
<target.model.location>${project.build.directory}/generated-sources/swagger</target.model.location>
<target.model.model-package>org.swaggertools.demo.model</target.model.model-package>
<target.client.location>${project.build.directory}/generated-sources/swagger</target.client.location>
<target.client.model-package>org.swaggertools.demo.model</target.client.model-package>
<target.client.client-package>org.swaggertools.demo.client</target.client.client-package>
</options>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Check also a complete sample application: demo-webmvc
There is no specific gradle plugin yet, but you can run code generator from gradle using command line version:
configurations {
swagger
}
dependencies {
swagger 'com.github.agliznetsov.swagger-tools:swagger-tools-cli:0.8.3'
}
task "swagger-generate"(type: JavaExec) {
classpath = configurations.swagger
main = 'org.swaggertools.cli.Generator'
args = [
"--source.location", "src/main/resources/swagger.yaml",
"--target.model.location", "src/main/java",
"--target.model.model-package", "com.example.model",
]
}
Additional targets can be added via java ServiceLoader: