https://github.com/agliznetsov/swagger-tools
Code generator to produce java client and server mappings from Swagger / OpenAPI REST API definition.
https://github.com/agliznetsov/swagger-tools
code-generation java maven-plugin oas open-api open-api-v3 swagger
Last synced: 4 months ago
JSON representation
Code generator to produce java client and server mappings from Swagger / OpenAPI REST API definition.
- Host: GitHub
- URL: https://github.com/agliznetsov/swagger-tools
- Owner: agliznetsov
- License: mit
- Created: 2018-06-01T12:37:24.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-25T11:00:48.000Z (about 2 years ago)
- Last Synced: 2025-03-20T05:30:53.777Z (about 1 year ago)
- Topics: code-generation, java, maven-plugin, oas, open-api, open-api-v3, swagger
- Language: Java
- Homepage:
- Size: 371 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# swagger-tools
[](https://travis-ci.org/agliznetsov/swagger-tools)
[](https://repo1.maven.org/maven2/com/github/agliznetsov/swagger-tools/swagger-tools-cli)
## Overview
This project provides a set of tools to generate java code from API definition.
### Source
- Swagger 2.0 or OpenAPI 3.0 API definition in json/yaml format
- Extensions
- **x-ignore** to exclude operations from the code generation process
- **x-ignore-server** to exclude operations from the server code generation process
- **x-ignore-server-client** to exclude operations from the client code generation process
- **x-name** to specify OpenAPI 3 requestBody parameter name
- **x-base-path** to specify OpenAPI 3 API base path
- **x-response-entity** to make Client/Server return Spring ResponseEntity object
- **x-model-package** to specify package name for the model classes
### Targets
- Model classes. Supported dialects:
- Jackson2
- Java client SDK, can be used for unit testing or to create java client applications. Supported dialects:
- Spring RestTemplate
- Spring WebClient
- Apache HttpClient
- Server API interfaces with HTTP mapping annotations. Supported dialects:
- Spring WebMVC
- Spring Webflux
- JAX-RS
### Run from command line
To get list of arguments:
`java -jar swagger-tools-cli.jar`
To generate models and client code:
```sh
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 \
```
### Run from maven
```xml
com.github.agliznetsov.swagger-tools
swagger-tools-maven-plugin
0.2.0
petstore
generate
${project.basedir}/src/main/resources/petstore.yaml
${project.build.directory}/generated-sources/swagger
org.swaggertools.demo.model
${project.build.directory}/generated-sources/swagger
org.swaggertools.demo.model
org.swaggertools.demo.client
```
#### Plugin configuration parameters:
- **skip**: Skip code generation
- **help**: Print the list of options
- **options**: Key/Value map of arguments for the code generator. Same as for the commandline version.
Check also a complete sample application: [demo-webmvc](demo/demo-webmvc)
### Run from gradle
There is no specific gradle plugin yet, but you can run code generator from gradle using command line version:
```groovy
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",
]
}
```
### Extensions
Additional targets can be added via java [ServiceLoader](https://docs.oracle.com/javase/tutorial/ext/basics/spi.html):
- Implement [Target](swagger-tools-core/src/main/java/org/swaggertools/core/run/Target.java) interface
- List it in the META-INF/services
- Add your jar file to the classpath of the CLI or maven plugin