OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Go to file
2018-06-12 06:40:07 +02:00
.github Update PULL_REQUEST_TEMPLATE.md 2018-05-19 07:39:26 +02:00
.mvn/wrapper #7093 - Add maven wrapper (#7356) 2018-01-22 14:35:34 +08:00
bin Prepare 3.0.1 release (#280) 2018-06-11 10:32:15 -04:00
CI Initial commit for 4.0.0-SNAPSHOT 2018-06-12 06:40:07 +02:00
docs Updates small typo in qna.md (#262) 2018-06-09 09:21:44 -04:00
modules Initial commit for 4.0.0-SNAPSHOT 2018-06-12 06:40:07 +02:00
samples Initial commit for 4.0.0-SNAPSHOT 2018-06-12 06:40:07 +02:00
.dockerignore [docker] Cleanup and reduce container sizes 2016-05-23 21:54:35 -04:00
.gitignore [gradle] Plugin release management (#201) 2018-06-09 14:21:31 -04:00
.java-version [Swift4]Update templates for swift 4 (#6921) 2017-11-21 11:33:52 +08:00
.travis.yml Update sec.gpg.enc to binary encoded secret 2018-06-09 23:03:44 -04:00
appveyor.yml Reduce CI logging (#119) 2018-05-21 23:15:51 +08:00
circle.yml Fix ivy2 cache directory in CI config file (#161) 2018-05-27 15:44:26 -04:00
CODE_OF_CONDUCT.md Various updates (#419) 2018-05-11 15:28:32 +08:00
CONTRIBUTING.md Various updates (#419) 2018-05-11 15:28:32 +08:00
docker-entrypoint.sh [cli] Completions command for suggestions (#213) 2018-06-10 19:33:00 +08:00
Dockerfile Changes for Docker (#400) 2018-05-11 11:41:42 +08:00
eclipse-formatter.xml Allow Java source formatting mvn formatter:format (#4214) 2016-11-23 15:07:25 +08:00
google_checkstyle.xml Spelling fixes (#7142) 2017-12-10 10:48:30 +08:00
LICENSE update file header (#282) 2018-05-01 18:50:48 +08:00
mvnw #7093 - Add maven wrapper (#7356) 2018-01-22 14:35:34 +08:00
mvnw.cmd #7093 - Add maven wrapper (#7356) 2018-01-22 14:35:34 +08:00
new.sh Cli generator name option, replaces 'language' options in CLI and Maven Plugin (#57) 2018-05-23 05:41:19 +02:00
pom.xml Initial commit for 4.0.0-SNAPSHOT 2018-06-12 06:40:07 +02:00
README.md Prepare 3.0.2-SNAPSHOT (#285) 2018-06-11 13:22:03 -04:00
run-in-docker.sh Add OpenAPI spec 3.0 support (beta) 2018-04-17 09:19:10 +02:00
sec.gpg.enc Update sec.gpg.enc to binary encoded secret 2018-06-09 23:03:44 -04:00
shippable.yml Prepare 3.0.2-SNAPSHOT (#285) 2018-06-11 13:22:03 -04:00
Vagrantfile Various updates (#419) 2018-05-11 15:28:32 +08:00

OpenAPI Generator

Master (3.0.0): Build Status Integration Test2 Run Status Windows Test

Join the chat at https://gitter.im/OpenAPITools/openapi-generator

If you would like to contribute, please refer to guidelines and a list of open tasks.

‼️ To migrate from Swagger Codegen to OpenAPI Generator, please refer to the migration guide ‼️

📔 For more information, please refer to the Wiki page and FAQ 📔

📔 The eBook A Beginner's Guide to Code Generation for REST APIs is a good starting point for begineers 📔

⚠️ 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 may occur ⚠️

Overview

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (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), Kotlin, PHP (Lumen, Slim, Silex, Symfony, Zend Expressive), Python (Flask), NodeJS, Ruby (Sinatra, Rails5), Rust (rust-server), Scala (Finch, Lagom, Scalatra)
API documentation generators HTML, Confluence Wiki
Configuration files Apache2
Others JMeter

Table of contents

1 - Installation

1.1 - Compatibility

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.2 (current master, upcoming release) SNAPSHOT TBD 1.0, 1.1, 1.2,
3.0.1 11.06.2018 1.0, 1.1, 1.2, 2.0, 3.0 Bugfix release
3.0.0 01.06.2018 1.0, 1.1, 1.2, 2.0, 3.0 First release with breaking changes

1.2 - Artifacts on Maven Central

You can find our released artefacts on maven central:

Core:

<dependency>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator</artifactId>
    <version>${openapi-generator-version}</version>
</dependency>

Cli:

<dependency>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-cli</artifactId>
    <version>${openapi-generator-version}</version>
</dependency>

Maven plugin:

<dependency>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>${openapi-generator-version}</version>
</dependency>

Gradle plugin:

<dependency>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-gradle-plugin</artifactId>
    <version>${openapi-generator-version}</version>
</dependency>

1.3 - Download JAR

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:

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 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:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
export PATH=${JAVA_HOME}/bin:$PATH

1.4 - Build Projects

To build from source, you need the following installed and available in your $PATH:

After cloning the project, you can build it from source with this command:

mvn clean install

If you don't have maven installed, you may directly use the included maven wrapper, and build with the command:

./mvnw clean install

1.5 - Homebrew

To install, run brew install openapi-generator (the new brew formula is pending https://github.com/Homebrew/homebrew-core/pull/28584)

Here is an example usage to generate a Ruby client:

openapi-generator generate -i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ruby -o /tmp/test/

1.6 - Docker

Public Pre-built Docker images

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:

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 \
    -g 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:

# Start container at port 8888 and save the container id
> CID=$(docker run -d -p 8888:8080 -e GENERATOR_HOST=http://localhost:8888 openapitools/openapi-generator-online)

# allow for startup
> sleep 10

# Get the IP of the running container (optional)
GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}'  $CID)

# Execute an HTTP request to generate a Ruby client
> curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' \
-d '{"openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"}' \
'http://localhost:8888/api/gen/clients/ruby'

{"code":"c2d483d3-3672-40e9-91df-b9ffd18d22b8","link":"http://localhost:8888/api/gen/download/c2d483d3-3672-40e9-91df-b9ffd18d22b8"}

# Download the generated zip file  
> wget http://localhost:8888/api/gen/download/c2d483d3-3672-40e9-91df-b9ffd18d22b8

# Unzip the file
> unzip c2d483d3-3672-40e9-91df-b9ffd18d22b8

# Shutdown the openapi generator image
> docker stop $CID && docker rm $CID

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:

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:

./run-in-docker.sh help # Executes 'help' command for openapi-generator-cli
./run-in-docker.sh list # Executes 'list' 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 \
    -g go -o /gen/out/go-petstore -DpackageName=petstore # generates go client, outputs locally to ./out/go-petstore

Run Docker in Vagrant

Prerequisite: install Vagrant and VirtualBox.

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

To generate a PHP client for petstore.yaml, please run the following

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 \
   -g 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 -g php -o c:\temp\php_api_client)

You can also download the JAR (latest release) directly from maven.org

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 -g php

3 - Usage

To generate a sample client library

You can build a client against the Petstore API as follows:

./bin/java-petstore.sh

(On Windows, run .\bin\windows\java-petstore.bat instead)

This will run the generator with this command:

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 \
  -g 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 the specified
        generator.

SYNOPSIS
        openapi-generator-cli generate
                [(-a <authorization> | --auth <authorization>)]
                [--additional-properties <additional properties>...]
                [--api-package <api package>] [--artifact-id <artifact id>]
                [--artifact-version <artifact version>]
                [(-c <configuration file> | --config <configuration file>)]
                [-D <system properties>...]
                [(-g <generator name> | --generator-name <generator name>)]
                [--git-repo-id <git repo id>] [--git-user-id <git user id>]
                [--group-id <group id>] [--http-user-agent <http user agent>]
                (-i <spec file> | --input-spec <spec file>)
                [--ignore-file-override <ignore file override location>]
                [--import-mappings <import mappings>...]
                [--instantiation-types <instantiation types>...]
                [--invoker-package <invoker package>]
                [(-l <language> | --lang <language>)]
                [--language-specific-primitives <language specific primitives>...]
                [--library <library>] [--model-name-prefix <model name prefix>]
                [--model-name-suffix <model name suffix>]
                [--model-package <model package>]
                [(-o <output directory> | --output <output directory>)]
                [--release-note <release note>] [--remove-operation-id-prefix]
                [--reserved-words-mappings <reserved word mappings>...]
                [(-s | --skip-overwrite)]
                [(-t <template directory> | --template-dir <template directory>)]
                [--type-mappings <type mappings>...] [(-v | --verbose)]

OPTIONS
        -a <authorization>, --auth <authorization>
            adds authorization headers when fetching the OpenAPI definitions
            remotely. Pass in a URL-encoded string of name:header with a comma
            separating multiple values

...... (results omitted)

        -v, --verbose
            verbose mode

You can then compile and run the client, as well as unit tests against it:

cd samples/client/petstore/java
mvn package

Other languages have petstore samples, too:

./bin/android-petstore.sh
./bin/java-petstore.sh
./bin/objc-petstore.sh

3.1 - Customization

Please refer to customization.md on how to customize the output (e.g. package name, version)

3.2 - Workflow Integration (Maven, Gradle, Github, CI/CD)

Please refer to integration.md on how to integrate OpenAPI generator with Maven, Gradle, Github and CI/CD.

3.3 - Online OpenAPI generator

Please refer to online-openapi-generator.md on how to run and use the openapi-generator-online - a web service for openapi-generator.

3.4 - License information on Generated Code

The OpenAPI Generator project is intended as a benefit for users of the Open API Specification. The project itself has the License as specified. In addition, please understand the following points:

  • The templates included with this project are subject to the License.
  • Generated code is intentionally not subject to the parent project license

When code is generated from this project, it shall be considered AS IS and owned by the user of the software. There are no warranties--expressed or implied--for generated code. You can do what you wish with it, and once generated, the code is your responsibility and subject to the licensing terms that you deem appropriate.

4 - Companies/Projects using OpenAPI Generator

Here are some companies/projects (alphabetical order) using OpenAPI Generator in production. To add your company/project to the list, please visit README.md and click on the icon to edit the page.

5 - Presentations/Videos/Tutorials/Books

6 - About Us

6.1 - OpenAPI Generator Core Team

OpenAPI Generator core team members are contributors who have been making significant contributions (review issues, fix bugs, make enhancements, etc) to the project on a regular basis.

Core Team Members

Template Creator

Here is a list of template creators:

  • API Clients:
    • Ada: @stcarrez
    • Akka-Scala: @cchafer
    • Apex: @asnelling
    • Bash: @bkryza
    • C++ REST: @Danielku15
    • C# (.NET 2.0): @who
    • C# (.NET Standard 1.3 ): @Gronsak
    • C# (.NET 4.5 refactored): @jimschubert
    • Clojure: @xhh
    • Dart: @yissachar
    • Dart (refactored in 2.4.0): @joernahrens
    • Elixir: @niku
    • Elm: @trenneman
    • Eiffel: @jvelilla
    • Erlang: @tsloughter
    • Groovy: @victorgit
    • Go: @wing328
    • Go (rewritten in 2.3.0): @antihax
    • Haskell (http-client): @jonschoning
    • Java (Feign): @davidkiss
    • Java (Retrofit): @0legg
    • Java (Retrofit2): @emilianobonassi
    • Java (Jersey2): @xhh
    • Java (okhttp-gson): @xhh
    • Java (RestTemplate): @nbruno
    • Java (RESTEasy): @gayathrigs
    • Java (Vertx): @lopesmcc
    • Java (Google APIs Client Library): @charlescapps
    • Java (Rest-assured): @viclovsky
    • Javascript/NodeJS: @jfiala
    • Javascript (Closure-annotated Angular) @achew22
    • JMeter: @davidkiss
    • Kotlin: @jimschubert
    • Lua: @daurnimator
    • Perl: @wing328
    • PHP (Guzzle): @baartosz
    • PowerShell: @beatcracker
    • R: @ramnov
    • Rust: @farcaller
    • Rust (rust-server): @metaswitch
    • Scala (scalaz & http4s): @tbrown1979
    • Swift: @tkqubo
    • Swift 3: @hexelon
    • Swift 4: @ehyche
    • TypeScript (Node): @mhardorf
    • TypeScript (Angular1): @mhardorf
    • TypeScript (Fetch): @leonyu
    • TypeScript (Angular2): @roni-frantchi
    • TypeScript (jQuery): @bherila
  • Server Stubs
    • Ada: @stcarrez
    • C# ASP.NET5: @jimschubert
    • C# NancyFX: @mstefaniuk
    • C++ Pistache: @sebymiano
    • C++ Restbed: @stkrwork
    • Erlang Server: @galaxie
    • Go Server: @guohuang
    • Haskell Servant: @algas
    • Java MSF4J: @sanjeewa-malalgoda
    • Java Spring Boot: @diyfr
    • Java Undertow: @stevehu
    • Java Play Framework: @JFCote
    • Java PKMST: @anshu2185 @sanshuman @rkumar-pk @ninodpillai
    • JAX-RS RestEasy: @chameleon82
    • JAX-RS CXF: @hiveship
    • JAX-RS CXF (CDI): @nickcmaynard
    • JAX-RS RestEasy (JBoss EAP): @jfiala
    • Kotlin: @jimschubert
    • PHP Lumen: @abcsun
    • PHP Slim: @jfastnacht
    • PHP Symfony: @ksm2
    • PHP Zend Expressive (with Path Handler): @Articus
    • Ruby on Rails 5: @zlx
    • Rust (rust-server): @metaswitch
    • Scala Finch: @jimschubert
    • Scala Lagom: @gmkumar2005
  • Documentation
    • HTML Doc 2: @jhitchcock
    • Confluence Wiki: @jhitchcock
  • Configuration
    • Apache2: @stkrwork

How to join the core team

Here are the requirements to become a core team member:

To join the core team, please reach out to team@openapitools.org for more information.

To become a Template Creator, simply submit a PR for new API client (e.g. Rust, Elixir) or server stub (e.g. Ruby Grape) generator.

6.2 - OpenAPI Generator Technical Committee

Members of the OpenAPI Generator technical committee shoulder the following responsibilities:

  • Provides guidance and direction to other users
  • Reviews pull requests and issues
  • Improves the generator by making enhancements, fixing bugs or updating documentations
  • Sets the technical direction of the generator

Who is eligible? Those who want to join must have at least 3 PRs merged into a generator. (Exceptions can be granted to template creators or contributors who have made a lot of code changes with less than 3 merged PRs)

If you want to join the committee, please kindly apply by sending an email to team@openapitools.org with your Github ID.

Members of Technical Committee

Languages Member (join date)
ActionScript
Ada @stcarrez (2018/02) @micheleISEP (2018/02)
Android @jaz-ah (2017/09)
Apex
Bash @frol (2017/07) @bkryza (2017/08) @kenjones-cisco (2017/09)
C++ @ravinikam (2017/07) @stkrwork (2017/07) @fvarose (2017/11) @etherealjoy (2018/02) @martindelille (2018/03)
C# @mandrean (2017/08) @jimschubert (2017/09)
Clojure
Dart @ircecho (2017/07)
Eiffel @jvelilla (2017/09)
Elixir
Elm
Erlang @tsloughter (2017/11)
Groovy
Go @antihax (2017/11) @bvwells (2017/12)
Haskell
Java @bbdouglas (2017/07) @JFCote (2017/08) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01)
Kotlin @jimschubert (2017/09)
Lua @daurnimator (2017/08)
NodeJS/Javascript @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07)
ObjC
Perl @wing328 (2017/07)
PHP @jebentier (2017/07) @dkarlovi (2017/07) @mandrean (2017/08) @jfastnacht (2017/09) @ackintosh (2017/09)
Python @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11)
R
Ruby @cliffano (2017/07) @zlx (2017/09)
Rust @frol (2017/07) @farcaller (2017/08) @bjgill (2017/12)
Scala @clasnake (2017/07) @jimschubert (2017/09) @shijinkui (2018/01) @ramzimaalej (2018/03)
Swift @jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @d-date (2018/03)
TypeScript @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01)

6.3 - History of OpenAPI Generator

OpenAPI Generator is a fork of Swagger Codegen. In view of the issues with the Swagger Codegen 3.0.0 (beta) release and the disagreement on the project's direction, more than 40 top contributors and template creators of Swagger Codegen decided to fork Swagger Codegen and maintain a community-driven version called "OpenAPI Generator". Please refer to the Q&A for more information.

Founding Members (alphabetical order):

7 - License


Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
Copyright 2018 SmartBear Software

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.