OpenAPI Generator is a tool that can generate API clients and server stubs using as an input an OpenAPI or Swagger specification file. It's a fork of the swagger-codegen generator that can be launched using a CLI with npm, docker and Homebrew.
The full list of supported Languages/Frameworks is available in the following link: https://openapi-generator.tech/docs/generators
Maven and Gradle plugins are also available to automate the code generation in your existing projects.
Installationnpm install @openapitools/openapi-generator-cli -g
To generate your REST API server or client from an OpenAPI file, run the following command:
openapi-generator generate -i <openapi-file> -g <generator-id> -o <output-path>
with the parameters being:
<openapi-file>
: the OpenAPI file path<generator-id>
: the name of the language / framework (as listed here, can also be listed using openapi-generator list
)<output-path>
: the path where the project will be generatedopenapi-generator generate -i my-api.yaml -g spring -o C:\tmp\my-api
Advanced usage
You can customize the generated project package name and other aspects using command line flags that can be listed with the command openapi-generator help generate
.
With the -c <configuration file>
flag, you can specify the path of a file containing configuration properties specific to the chosen language / framework. This file can be either json or yaml formatted. The supported properties for each language can be listed with openapi-generator config-help -g <generator-id>
or can be viewed by selecting the appropriate entry in https://openapi-generator.tech/docs/generators.
config.json
:
{
"basePackage": "com.myorg.myapp",
"configPackage": "com.myorg.myapp.config",
"apiPackage": "com.myorg.myapp.controllers",
"modelPackage": "com.myorg.myapp.domain",
"groupId": "com.myorg",
"artifactId": "my-app",
"artifactVersion": "0.1.0"
}
openapi-generator generate -i my-api.yaml -g spring -c config.json -o C:\tmp\my-api
Note
The configuration properties can also be specified from the command line using the flag: --additional-properties=key1=value1,key2=value2
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4