# Swagger Code Generator [![Build Status](https://travis-ci.org/swagger-api/swagger-codegen.svg)](https://travis-ci.org/swagger-api/swagger-codegen) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project/badge.svg?style=plastic)](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project) [![PR Stats](http://issuestats.com/github/swagger-api/swagger-codegen/badge/pr)](http://issuestats.com/github/swagger-api/swagger-codegen) [![Issue Stats](http://issuestats.com/github/swagger-api/swagger-codegen/badge/issue)](http://issuestats.com/github/swagger-api/swagger-codegen) :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%22Need+community+contribution%22).:star::star::star: ## Overview This is the swagger codegen project, which allows generation of client libraries automatically from a Swagger-compliant server. Check out [Swagger-Spec](https://github.com/OAI/OpenAPI-Specification) for additional information about the Swagger project, including additional libraries with support for other languages and more. # Table of contents - [Swagger Code Generator](#swagger-code-generator) - [Overview](#overview) - [Table of Contents](#table-of-contents) - Installation - [Compatibility](#compatibility) - [Prerequisites](#prerequisites) - [OS X Users](#os-x-users) - [Building](#building) - [Docker](#docker) - [Build and run](#build-and-run-using-docker) - [Run docker in Vagrant](#run-docker-in-vagrant) - [Public Docker image](#public-docker-image) - [Homebrew](#homebrew) - 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) - [Node.js](#nodejs) - [PHP Slim](#php-slim) - [PHP Silex](#php-silex) - [Python Flask (Connexion)](#python-flask-connexion) - [Ruby Sinatra](#ruby-sinatra) - [Scala Scalatra](#scala-scalatra) - [Java JAX-RS (Java JAX-RS (Jersey v1.18)](#java-jax-rs-jersey-v118) - [Java JAX-RS (Apache CXF 2 / 3)](#java-jax-rs-apache-cxf-2--3) - [Java JAX-RS (Resteasy)](#java-jax-rs-resteasy) - [Java Spring MVC](#java-spring-mvc) - [Haskell Servant](#haskell-servant) - [ASP.NET 5 Web API](#aspnet-5-web-api) - [To build the codegen library](#to-build-the-codegen-library) - [Workflow Integration](#workflow-integration) - [Github Integration](#github-integration) - [Online Generators](#online-generators) - [Guidelines for Contribution](https://github.com/swagger-api/swagger-codegen/wiki/Guidelines-for-Contribution) - [Companies/Projects using Swagger Codegen](#companiesprojects-using-swagger-codegen) - [License](#license) ## Compatibility The OpenAPI Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the OpenAPI Specification: Swagger Codegen Version | Release Date | OpenAPI Spec compatibility | Notes -------------------------- | ------------ | -------------------------- | ----- 2.1.7-SNAPSHOT | | 1.0, 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-codegen) 2.1.6 (**current stable**) | 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.5) 2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/v2.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 central (you'll need java 7 runtime at a minimum): ``` wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.1.5/swagger-codegen-cli-2.1.6.jar -O swagger-codegen-cli.jar java -jar swagger-codegen-cli.jar help ``` On a mac, it's even easier with `brew`: ``` brew install swagger-codegen ``` To build from source, you need the following installed and available in your $PATH: * [Java 7 or 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 7 or 8. You probably have 1.6. 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 ``` ### Building After cloning the project, you can build it from source with this command: ``` mvn package ``` ### Docker #### Build and run using docker ``` git clone https://github.com/swagger-api/swagger-codegen cd swagger-codegen ./run-in-docker.sh mvn package ``` #### Run Docker in Vagrant Prerequisite: install [Vagrant](https://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads). ``` 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 Docker image https://hub.docker.com/r/swaggerapi/swagger-generator/ ### Homebrew To install, run `brew install swagger-codegen` Here is an example usage: ``` swagger-codegen generate -i http://petstore.swagger.io/v2/swagger.json -l ruby -o /tmp/test/ ``` ### To generate a sample client library You can build a client against the swagger sample [petstore](http://petstore.swagger.io) 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/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i http://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: ``` 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 ] [--group-id ] (-i | --input-spec ) [--import-mappings ] [--instantiation-types ] [--invoker-package ] (-l | --lang ) [--language-specific-primitives ] [--library ] [--model-package ] [(-o | --output )] [(-s | --skip-overwrite)] [(-t