OpenAPI Generator

Master (3.0.0): [![Build Status](https://travis-ci.org/OpenAPITools/openapi-generator.svg?branch=master)](https://travis-ci.org/OpenAPITools/openapi-generator) [![Integration Test2](https://circleci.com/gh/OpenAPITools/openapi-generator.svg?style=shield)](https://circleci.com/gh/OpenAPITools/openapi-generator) [![Run Status](https://img.shields.io/shippable/5782588a3be4f4faa56c5bea/master.svg?label=Template%20Test)](https://app.shippable.com/github/OpenAPITools/openapi-generator/dashboard) [![Windows Test](https://ci.appveyor.com/api/projects/status/github/openapitools/openapi-generator?branch=master&svg=true&passingText=Windows%20Test%20-%20OK&failingText=Windows%20Test%20-%20Fails)](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
[![Join the chat at https://gitter.im/OpenAPITools/openapi-generator](https://badges.gitter.im/OpenAPITools/openapi-generator.svg)](https://gitter.im/OpenAPITools/openapi-generator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
:star::star::star: If you would like to contribute, please refer to [guidelines](CONTRIBUTING.md) and a list of [open tasks](https://github.com/openapitools/openapi-generator/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).:star::star::star: :bangbang: To migrate from Swagger Codegen to OpenAPI Generator, please refer to the [migration guide](docs/migration-from-swagger-codegen.md) :bangbang: :notebook_with_decorative_cover: For more information, please refer to the [Wiki page](https://github.com/openapitools/openapi-generator/wiki) and [FAQ](https://github.com/openapitools/openapi-generator/wiki/FAQ) :notebook_with_decorative_cover: :notebook_with_decorative_cover: The eBook [A Beginner's Guide to Code Generation for REST APIs](https://gumroad.com/l/swagger_codegen_beginner) is a good starting point for begineers :notebook_with_decorative_cover: :warning: If the OpenAPI spec is obtained from an untrusted source, please make sure you've reviewed the spec before using OpenAPI Generator to generate the API client, server stub or documentation as [code injection](https://en.wikipedia.org/wiki/Code_injection) may occur :warning:
## Overview OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification) (both 2.0 and 3.0 are supported). Currently, the following languages/frameworks are supported: | | Languages/Frameworks | |-|-| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 6.x), Aurelia, Fetch, Inversify, jQuery, Node) **Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go**, **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin**, **PHP** (Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), Scalatra) **API documentation generators** | **HTML**, **Confluence Wiki** **Configuration files** | [**Apache2**](https://httpd.apache.org/) **Others** | **JMeter** ## Table of contents - [OpenAPI Generator](#openapi-generator) - [Overview](#overview) - [Table of Contents](#table-of-contents) - [1 - Installation](#1---installation) - [1.1 - Compatibility](#11---compatibility) - [1.2 - Download JAR](#12---download-jar) - [1.3 - Build Projects](#13---build-projects) - [1.4 - Homebrew](#14---homebrew) - [1.5 - Docker](#15---docker) - [2 - Getting Started](#2---getting-started) - [3 - Usage](#3---usage) - [3.1 - Customization](#31---customization) - [3.2 - Workflow Integration](#32---workflow-integration-maven-gradle-github-cicd) - [3.3 - Online Generators](#33---online-openapi-generator) - [3.4 - License Information on Generated Code](#34---license-information-on-generated-code) - [4 - Companies/Projects using OpenAPI Generator](#4---companiesprojects-using-openapi-generator) - [5 - Presentations/Videos/Tutorials/Books](#5---presentationsvideostutorialsbooks) - [6 - About Us](#6---about-us) - [6.1 - OpenAPI Generator Core Team](#61---openapi-generator-core-team) - [6.2 - OpenAPI Generator Technical Committee](#62---openapi-generator-technical-committee) - [6.3 - History of OpenAPI Generator](#63---history-of-openapi-generator) - [7 - License](#7---license) ## [1 - Installation](#table-of-contents) ### [1.1 - Compatibility](#table-of-contents) The OpenAPI Specification has undergone 3 revisions since initial creation in 2010. The openapi-generator project has the following compatibilities with the OpenAPI Specification: OpenAPI Generator Version | Release Date | OpenAPI Spec compatibility | Notes ---------------------------- | ------------ | -------------------------- | ----- 4.0.0 (upcoming major release) | TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Major release with breaking changes (no fallback) 3.1.0 (upcoming minor release) | TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks) 3.0.0 (current master, upcoming release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.0.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | First release with breaking changes ### [1.2 - Download JAR](#table-of-contents) If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum): JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.0/openapi-generator-cli-3.0.0.jar` For **Mac/Linux** users: ```sh wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.0/openapi-generator-cli-3.0.0.jar -O openapi-generator-cli.jar ``` For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g. ``` Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.0/openapi-generator-cli-3.0.0.jar ``` After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage. For Mac users, please make sure Java 8 is installed (Tips: run `java -version` to check the version), and export `JAVA_HOME` in order to use the supported Java version: ```sh export JAVA_HOME=`/usr/libexec/java_home -v 1.8` export PATH=${JAVA_HOME}/bin:$PATH ``` ### [1.3 - Build Projects](#table-of-contents) To build from source, you need the following installed and available in your `$PATH:` * [Java 8](http://java.oracle.com) * [Apache maven 3.3.3 or greater](http://maven.apache.org/) After cloning the project, you can build it from source with this command: ```sh mvn clean install ``` If you don't have maven installed, you may directly use the included [maven wrapper](https://github.com/takari/maven-wrapper), and build with the command: ```sh ./mvnw clean install ``` ### [1.4 - Homebrew](#table-of-contents) To install, run `brew install openapi-generator` Here is an example usage to generate a Ruby client: ```sh openapi-generator generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l ruby -o /tmp/test/ ``` ### [1.5 - Docker](#table-of-contents) #### Public Pre-built Docker images - [https://hub.docker.com/r/openapitools/openapi-generator-online/](https://hub.docker.com/r/openapitools/openapi-generator-online/) (official web service) - [https://hub.docker.com/r/openapitools/openapi-generator-cli/](https://hub.docker.com/r/openapitools/openapi-generator-cli/) (official CLI) #### OpenAPI Generator CLI Docker Image The OpenAPI Generator image acts as a standalone executable. It can be used as an alternative to installing via homebrew, or for developers who are unable to install Java or upgrade the installed version. To generate code with this image, you'll need to mount a local location as a volume. Example: ```sh docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \ -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \ -l go \ -o /local/out/go ``` The generated code will be located under `./out/go` in the current directory. #### OpenAPI Generator Online Docker Image The openapi-generator-online image can act as a self-hosted web application and API for generating code. This container can be incorporated into a CI pipeline, and requires at least two HTTP requests and some docker orchestration to access generated code. Example usage (note this assumes `jq` is installed for command line processing of JSON): ```sh # Start container and save the container id CID=$(docker run -d openapitools/openapi-generator-online) # allow for startup sleep 5 # Get the IP of the running container GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' $CID) # Execute an HTTP request and store the download link RESULT=$(curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "swaggerUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml" }' 'http://localhost:8188/api/gen/clients/python' | jq '.link' | tr -d '"') # Download the generated zip and redirect to a file curl $RESULT > result.zip # Shutdown the swagger generator image docker stop $CID && docker rm $CID ``` In the example above, `result.zip` will contain the generated client. #### Development in docker You can use `run-in-docker.sh` to do all development. This script maps your local repository to `/gen` in the docker container. It also maps `~/.m2/repository` to the appropriate container location. To execute `mvn package`: ```sh git clone https://github.com/openapitools/openapi-generator cd openapi-generator ./run-in-docker.sh mvn package ``` Build artifacts are now accessible in your working directory. Once built, `run-in-docker.sh` will act as an executable for openapi-generator-cli. To generate code, you'll need to output to a directory under `/gen` (e.g. `/gen/out`). For example: ```sh ./run-in-docker.sh help # Executes 'help' command for openapi-generator-cli ./run-in-docker.sh langs # Executes 'langs' command for openapi-generator-cli ./run-in-docker.sh /gen/bin/go-petstore.sh # Builds the Go client ./run-in-docker.sh generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml \ -l go -o /gen/out/go-petstore -DpackageName=petstore # generates go client, outputs locally to ./out/go-petstore ``` #### Run Docker in Vagrant Prerequisite: install [Vagrant](https://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads). ```sh git clone http://github.com/openapitools/openapi-generator.git cd openapi-generator vagrant up vagrant ssh cd /vagrant ./run-in-docker.sh mvn package ``` ## [2 - Getting Started](#table-of-contents) To generate a PHP client for [petstore.yaml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml), please run the following ```sh git clone https://github.com/openapitools/openapi-generator cd openapi-generator mvn clean package java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \ -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \ -l php \ -o /var/tmp/php_api_client ``` (if you're on Windows, replace the last command with `java -jar modules\openapi-generator-cli\target\openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l php -o c:\temp\php_api_client`) You can also download the JAR (latest release) directly from [maven.org](http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.0.0/openapi-generator-cli-3.0.0.jar) To get a list of **general** options available, please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar help generate` To get a list of PHP specified options (which can be passed to the generator with a config file via the `-c` option), please run `java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar config-help -l php` ## [3 - Usage](#table-of-contents) ### To generate a sample client library You can build a client against the [Petstore API](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml) as follows: ```sh ./bin/java-petstore.sh ``` (On Windows, run `.\bin\windows\java-petstore.bat` instead) This will run the generator with this command: ```sh java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \ -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \ -l java \ -o samples/client/petstore/java ``` with a number of options. You can get the options with the `help generate` command (below only shows partial results): ``` NAME openapi-generator-cli generate - Generate code with chosen lang SYNOPSIS openapi-generator-cli generate [(-a | --auth )] [--additional-properties ...] [--api-package ] [--artifact-id ] [--artifact-version ] [(-c | --config )] [-D ...] [--git-repo-id ] [--git-user-id ] [--group-id ] [--http-user-agent ] (-i | --input-spec ) [--ignore-file-override ] [--import-mappings ...] [--instantiation-types ...] [--invoker-package ] (-l | --lang ) [--language-specific-primitives ...] [--library ] [--model-name-prefix ] [--model-name-suffix ] [--model-package ] [(-o | --output )] [--release-note ] [--remove-operation-id-prefix] [--reserved-words-mappings ...] [(-s | --skip-overwrite)] [(-t