# [![Build Status](https://img.shields.io/jenkins/build.svg?jobUrl=https://jenkins.swagger.io/job/oss-swagger-core-master-java-8)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-core-master-java-8) [![Build Status](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-master/badge/icon?subject=jenkins%20build)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-master/) [![Build Status](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-master-java7/badge/icon?subject=jenkins%20build%20-%20java%207)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-master-java7/) - Master (2.4.18-SNAPSHOT): [![Build Status](https://img.shields.io/travis/swagger-api/swagger-codegen/master.svg?label=Petstore%20Integration%20Test)](https://travis-ci.org/swagger-api/swagger-codegen) [![Java Test](https://img.shields.io/jenkins/build.svg?jobUrl=https://jenkins.swagger.io/job/oss-swagger-codegen-master)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-master) [![Windows Test](https://ci.appveyor.com/api/projects/status/github/swagger-api/swagger-codegen?branch=master&svg=true&passingText=Windows%20Test%20-%20OK&failingText=Windows%20Test%20-%20Fails)](https://ci.appveyor.com/project/swaggerhub-bot/swagger-codegen) - 3.0.24-SNAPSHOT: [![Build Status](https://img.shields.io/travis/swagger-api/swagger-codegen/3.0.0.svg?label=Petstore%20Integration%20Test)](https://travis-ci.org/swagger-api/swagger-codegen) [![Java Test](https://img.shields.io/jenkins/build.svg?jobUrl=https://jenkins.swagger.io/job/oss-swagger-codegen-3)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-3) [![Windows Test](https://ci.appveyor.com/api/projects/status/github/swagger-api/swagger-codegen?branch=3.0.0&svg=true&passingText=Windows%20Test%20-%20OK&failingText=Windows%20Test%20-%20Fails)](https://ci.appveyor.com/project/swaggerhub-bot/swagger-codegen) [Maven Central](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project) :star::star::star: If you would like to contribute, please refer to [guidelines](https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md) and a list of [open tasks](https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).:star::star::star: :notebook_with_decorative_cover: For more information, please refer to the [Wiki page](https://github.com/swagger-api/swagger-codegen/wiki) and [FAQ](https://github.com/swagger-api/swagger-codegen/wiki/FAQ) :notebook_with_decorative_cover: :warning: If the OpenAPI/Swagger spec is obtained from an untrusted source, please make sure you've reviewed the spec before using Swagger Codegen to generate the API client, server stub or documentation as [code injection](https://en.wikipedia.org/wiki/Code_injection) may occur :warning: :rocket: ProductHunt: https://producthunt.com/posts/swagger-codegen :rocket: :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 beginners. ## Versioning **NOTE:** version 2.X (`io.swagger`) and 3.X (`io.swagger.codegen.v3`) have **different** group ids. 2.X and 3.X version lines of Swagger Codegen are available; 2.X (`master` branch) supports Swagger/OpenAPI version 2, while 3.X ([`3.0.0` branch](https://github.com/swagger-api/swagger-codegen/tree/3.0.0)) supports OpenAPI version 3 (and version 2 via spec conversion to version 3). [Online generator of version 3.X](https://github.com/swagger-api/swagger-codegen/tree/3.0.0#online-generators) supports both generation from Swagger/OpenAPI version 2 (by using engine + generators of 2.X) and version 3 specifications. **NOTE:** this document refers to version 2.X, check [here](https://github.com/swagger-api/swagger-codegen/tree/3.0.0) for 3.X. ### Swagger Codegen 2.X ([`master` branch](https://github.com/swagger-api/swagger-codegen/tree/master)) Swagger Codegen 2.X supports Swagger/OpenAPI version 2. group id: `io.swagger` maven central (maven plugin): https://mvnrepository.com/artifact/io.swagger/swagger-codegen-maven-plugin dependency example: ``` io.swagger swagger-codegen-maven-plugin 2.4.17 ``` ### Swagger Codegen 3.X ([`3.0.0` branch](https://github.com/swagger-api/swagger-codegen/tree/3.0.0)) Swagger Codegen 3.X supports OpenAPI version 3 (and version 2 via spec conversion to version 3) [Online generator of version 3.X](https://github.com/swagger-api/swagger-codegen/tree/3.0.0#online-generators) supports both generation from Swagger/OpenAPI version 2 (by using engine + generators of 2.X) and version 3 specifications. group id: `io.swagger.codegen.v3` maven central: https://mvnrepository.com/artifact/io.swagger.codegen.v3 dependency example: ``` io.swagger.codegen.v3 swagger-codegen-maven-plugin 3.0.23 ``` ## Overview This is the Swagger Codegen project, which allows generation of API client libraries (SDK generation), server stubs and documentation automatically given an [OpenAPI Spec](https://github.com/OAI/OpenAPI-Specification). Currently, the following languages/frameworks are supported: - **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, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x, 5.x), **Typescript** (Angular1.x, Angular2.x, Fetch, 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** Check out [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) for additional information about the OpenAPI project. # Table of contents - [Versioning](#versioning) - [Overview](#overview) - [Table of Contents](#table-of-contents) - Installation - [Compatibility](#compatibility) - [Prerequisites](#prerequisites) - [OS X Users](#os-x-users) - [Building](#building) - [Docker](#docker) - [Development in Docker](#development-in-docker) - [Run docker in Vagrant](#run-docker-in-vagrant) - [Public pre-built Docker images](#public-pre-built-docker-images) - [Homebrew](#homebrew) - [Getting Started](#getting-started) - Generators - [To generate a sample client library](#to-generate-a-sample-client-library) - [Generating libraries from your server](#generating-libraries-from-your-server) - [Modifying the client library format](#modifying-the-client-library-format) - [Making your own codegen modules](#making-your-own-codegen-modules) - [Where is Javascript???](#where-is-javascript) - [Generating a client from local files](#generating-a-client-from-local-files) - [Customizing the generator](#customizing-the-generator) - [Validating your OpenAPI Spec](#validating-your-openapi-spec) - [Generating dynamic html api documentation](#generating-dynamic-html-api-documentation) - [Generating static html api documentation](#generating-static-html-api-documentation) - [To build a server stub](#to-build-a-server-stub) - [To build the codegen library](#to-build-the-codegen-library) - [Workflow Integration](#workflow-integration) - [Maven Integration](#maven-integration) - [Gradle Integration](#gradle-integration) - [Github Integration](#github-integration) - [Online Generators](#online-generators) - [Guidelines for Contribution](https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md#guidelines-for-contributing) - [Companies/Projects using Swagger Codegen](#companiesprojects-using-swagger-codegen) - [Presentations/Videos/Tutorials/Books](#presentationsvideostutorialsbooks) - [Swagger Codegen Core Team](#swagger-codegen-core-team) - [Swagger Codegen Technical Committee](#swagger-codegen-technical-committee) - [License](#license) ## Compatibility The OpenAPI Specification has undergone 3 revisions since initial creation in 2010. The Swagger Codegen project has the following compatibilities with the OpenAPI Specification: Swagger Codegen Version | Release Date | OpenAPI Spec compatibility | Notes -------------------------- | ------------ | -------------------------- | ----- 3.0.24-SNAPSHOT (current 3.0.0, upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/io/swagger/codegen/v3/swagger-codegen-cli/3.0.24-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release [3.0.23](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.23) (**current stable**) | 2020-11-02 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.23](https://github.com/swagger-api/swagger-codegen/tree/v3.0.23) [3.0.22](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.22) | 2020-10-05 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.22](https://github.com/swagger-api/swagger-codegen/tree/v3.0.22) [3.0.21](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.21) | 2020-07-28 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.21](https://github.com/swagger-api/swagger-codegen/tree/v3.0.21) [3.0.20](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.20) | 2020-05-18 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.20](https://github.com/swagger-api/swagger-codegen/tree/v3.0.20) [3.0.19](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.19) | 2020-04-02 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.19](https://github.com/swagger-api/swagger-codegen/tree/v3.0.19) [3.0.18](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.18) | 2020-02-26 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.18](https://github.com/swagger-api/swagger-codegen/tree/v3.0.18) [3.0.17](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.17) | 2020-02-23 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.17](https://github.com/swagger-api/swagger-codegen/tree/v3.0.17) [3.0.17](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.16) | 2020-01-15 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.16](https://github.com/swagger-api/swagger-codegen/tree/v3.0.16) [3.0.15](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.15) | 2020-01-03 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.15](https://github.com/swagger-api/swagger-codegen/tree/v3.0.15) [3.0.14](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.14) | 2019-11-16 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.14](https://github.com/swagger-api/swagger-codegen/tree/v3.0.14) [3.0.13](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.13) | 2019-10-16 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.13](https://github.com/swagger-api/swagger-codegen/tree/v3.0.13) [3.0.12](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.12) | 2019-10-14 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.12](https://github.com/swagger-api/swagger-codegen/tree/v3.0.12) [3.0.11](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.11) | 2019-08-24 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.11](https://github.com/swagger-api/swagger-codegen/tree/v3.0.11) [3.0.10](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.10) | 2019-07-11 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.10](https://github.com/swagger-api/swagger-codegen/tree/v3.0.10) [3.0.9](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.9) | 2019-06-28 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.9](https://github.com/swagger-api/swagger-codegen/tree/v3.0.9) [3.0.8](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.8) | 2019-04-25 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.8](https://github.com/swagger-api/swagger-codegen/tree/v3.0.8) [3.0.7](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.7) | 2019-03-26 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.7](https://github.com/swagger-api/swagger-codegen/tree/v3.0.7) [3.0.5](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.5) | 2019-02-18 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.5](https://github.com/swagger-api/swagger-codegen/tree/v3.0.5) [3.0.4](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.4) | 2019-01-16 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.4](https://github.com/swagger-api/swagger-codegen/tree/v3.0.4) [3.0.3](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.3) | 2018-11-30 | 1.0, 1.1, 1.2, 2.0, 3.0 | [tag v3.0.3](https://github.com/swagger-api/swagger-codegen/tree/v3.0.3) [3.0.2](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.2)| 2018-10-19 | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release [3.0.1](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.1)| 2018-10-05 | 1.0, 1.1, 1.2, 2.0, 3.0 | Major release with breaking changes [3.0.0](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.0)| 2018-09-06 | 1.0, 1.1, 1.2, 2.0, 3.0 | Major release with breaking changes 2.4.18-SNAPSHOT (current master, upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/2.4.18-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0 | Minor release [2.4.17](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.17) (**current stable**) | 2020-11-02 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.17](https://github.com/swagger-api/swagger-codegen/tree/v2.4.17) [2.4.16](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.16) | 2020-10-05 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.16](https://github.com/swagger-api/swagger-codegen/tree/v2.4.16) [2.4.15](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.15) | 2020-07-28 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.15](https://github.com/swagger-api/swagger-codegen/tree/v2.4.15) [2.4.14](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.14) | 2020-05-18 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.14](https://github.com/swagger-api/swagger-codegen/tree/v2.4.14) [2.4.13](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.13) | 2020-04-02 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.13](https://github.com/swagger-api/swagger-codegen/tree/v2.4.13) [2.4.12](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.12) | 2020-01-15 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.12](https://github.com/swagger-api/swagger-codegen/tree/v2.4.12) [2.4.11](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.11) | 2020-01-03 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.11](https://github.com/swagger-api/swagger-codegen/tree/v2.4.11) [2.4.10](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.10) | 2019-11-16 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.10](https://github.com/swagger-api/swagger-codegen/tree/v2.4.10) [2.4.9](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.9) | 2019-10-14 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.9](https://github.com/swagger-api/swagger-codegen/tree/v2.4.9) [2.4.8](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.8) | 2019-08-24 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.8](https://github.com/swagger-api/swagger-codegen/tree/v2.4.8) [2.4.7](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.7) | 2019-07-11 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.7](https://github.com/swagger-api/swagger-codegen/tree/v2.4.7) [2.4.6](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.6) | 2019-06-28 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.6](https://github.com/swagger-api/swagger-codegen/tree/v2.4.6) [2.4.5](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.5) | 2019-04-25 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.5](https://github.com/swagger-api/swagger-codegen/tree/v2.4.5) [2.4.4](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.4) | 2019-03-26 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.4](https://github.com/swagger-api/swagger-codegen/tree/v2.4.4) [2.4.2](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.2) | 2019-02-18 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.2](https://github.com/swagger-api/swagger-codegen/tree/v2.4.2) [2.4.1](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.1) | 2019-01-16 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.1](https://github.com/swagger-api/swagger-codegen/tree/v2.4.1) [2.4.0](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.4.0) | 2018-11-30 | 1.0, 1.1, 1.2, 2.0 | [tag v2.4.0](https://github.com/swagger-api/swagger-codegen/tree/v2.4.0) [2.3.1](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.3.1) | 2018-01-17 | 1.0, 1.1, 1.2, 2.0 | [tag v2.3.1](https://github.com/swagger-api/swagger-codegen/tree/v2.3.1) [2.3.0](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.3.0) | 2017-12-21 | 1.0, 1.1, 1.2, 2.0 | [tag v2.3.0](https://github.com/swagger-api/swagger-codegen/tree/v2.3.0) [2.2.3](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.2.3) | 2017-07-15 | 1.0, 1.1, 1.2, 2.0 | [tag v2.2.3](https://github.com/swagger-api/swagger-codegen/tree/v2.2.3) [2.2.2](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.2.2) | 2017-03-01 | 1.0, 1.1, 1.2, 2.0 | [tag v2.2.2](https://github.com/swagger-api/swagger-codegen/tree/v2.2.2) [2.2.1](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.2.1) | 2016-08-07 | 1.0, 1.1, 1.2, 2.0 | [tag v2.2.1](https://github.com/swagger-api/swagger-codegen/tree/v2.2.1) [2.1.6](https://github.com/swagger-api/swagger-codegen/releases/tag/v2.1.6) | 2016-04-06 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.6](https://github.com/swagger-api/swagger-codegen/tree/v2.1.6) 2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/2.0.17) 1.0.4 | 2012-04-12 | 1.0, 1.1 | [tag v1.0.4](https://github.com/swagger-api/swagger-codegen/tree/swagger-codegen_2.9.1-1.1) ### Prerequisites If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum): ```sh # Download current stable 2.x.x branch (Swagger and OpenAPI version 2) wget https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.17/swagger-codegen-cli-2.4.17.jar -O swagger-codegen-cli.jar java -jar swagger-codegen-cli.jar help # Download current stable 3.x.x branch (OpenAPI version 3) wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.23/swagger-codegen-cli-3.0.23.jar -O swagger-codegen-cli.jar java -jar swagger-codegen-cli.jar --help ``` 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 swagger-codegen-cli.jar https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.17/swagger-codegen-cli-2.4.17.jar` On a mac, it's even easier with `brew`: ```sh brew install swagger-codegen ``` 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/) #### OS X Users Don't forget to install Java 8+. 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 ``` ### Building After cloning the project, you can build it from source with this command: ```sh mvn clean package ``` 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 package ``` ### Homebrew To install, run `brew install swagger-codegen` Here is an example usage: ```sh swagger-codegen generate -i https://petstore.swagger.io/v2/swagger.json -l ruby -o /tmp/test/ ``` ### Docker #### 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/swagger-api/swagger-codegen cd swagger-codegen ./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 swagger-codegen-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 swagger-codegen-cli ./run-in-docker.sh langs # Executes 'langs' command for swagger-codegen-cli ./run-in-docker.sh /gen/bin/go-petstore.sh # Builds the Go client ./run-in-docker.sh generate -i modules/swagger-codegen/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 ``` #### Standalone generator Development in docker See [standalone generator development](https://github.com/swagger-api/swagger-codegen/blob/master/standalone-gen-dev/standalone-generator-development.md) #### 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/swagger-api/swagger-codegen.git cd swagger-codegen vagrant up vagrant ssh cd /vagrant ./run-in-docker.sh mvn package ``` #### Public Pre-built Docker images - https://hub.docker.com/r/swaggerapi/swagger-generator/ (official web service) - https://hub.docker.com/r/swaggerapi/swagger-codegen-cli/ (official CLI) ##### Swagger Generator Docker Image The Swagger Generator 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 swaggerapi/swagger-generator) # 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://petstore.swagger.io/v2/swagger.json" }' 'http://localhost:8188/api/gen/clients/javascript' | 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. ##### Swagger Codegen CLI Docker Image The Swagger Codegen 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 swaggerapi/swagger-codegen-cli generate \ -i https://petstore.swagger.io/v2/swagger.json \ -l go \ -o /local/out/go ``` (On Windows replace `${PWD}` with `%CD%`) The generated code will be located under `./out/go` in the current directory. ## Getting Started To generate a PHP client for https://petstore.swagger.io/v2/swagger.json, please run the following ```sh git clone https://github.com/swagger-api/swagger-codegen cd swagger-codegen mvn clean package java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i https://petstore.swagger.io/v2/swagger.json \ -l php \ -o /var/tmp/php_api_client ``` (if you're on Windows, replace the last command with `java -jar modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i https://petstore.swagger.io/v2/swagger.json -l php -o c:\temp\php_api_client`) You can also download the JAR (latest release) directly from [maven.org](https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.17/swagger-codegen-cli-2.4.17.jar) To get a list of **general** options available, please run `java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar help generate` (for version 3.x check [3.0.0 branch](https://github.com/swagger-api/swagger-codegen/tree/3.0.0)) 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/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l php` ## Generators ### To generate a sample client library You can build a client against the swagger sample [petstore](https://petstore.swagger.io) API 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/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i https://petstore.swagger.io/v2/swagger.json \ -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 swagger-codegen-cli generate - Generate code with chosen lang SYNOPSIS swagger-codegen-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