# Swagger Code Generator [![Build Status](https://travis-ci.org/swagger-api/swagger-codegen.png)](https://travis-ci.org/swagger-api/swagger-codegen) ## 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/swagger-api/swagger-spec) 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 - [Build and run using docker](#build-and-run-using-docker) - [Build a nodejs server stub](#build-a-nodejs-server-stub) - [Compatibility](#compatibility) - [Prerequisites](#prerequisites) - [OS X Users](#os-x-users) - [Building](#building) - 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 swagger spec](#validating-your-swagger-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) - [rails-grape](#rails-grape) - [scala scalatra](#scala-scalatra) - [java jax-rs](#java-jax-rs) - [java spring-mvc](#java-spring-mvc) - [To build the codegen library](#to-build-the-codegen-library) - [License](#license) ## Build and run using docker ``` git clone https://github.com/swagger-api/swagger-codegen cd swagger-codegen ./run-in-docker.sh mvn package ``` ## Build a nodejs server stub ``` ./run-in-docker.sh generate \ -i http://petstore.swagger.io/v2/swagger.json \ -l nodejs \ -o samples/server/petstore/nodejs ``` ## Compatibility The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the swagger specification: Swagger Codegen Version | Release Date | Swagger Spec compatibility | Notes -------------------------- | ------------ | -------------------------- | ----- 2.1.4-SNAPSHOT | | 1.0, 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-codegen) 2.1.3 (**current stable**) | 2015-08-24 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.3](https://github.com/swagger-api/swagger-codegen/tree/v2.1.3) 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 You need the following installed and available in your $PATH: * [Java 7](http://java.oracle.com) * [Apache maven 3.0.3 or greater](http://maven.apache.org/) #### OS X Users Don't forget to install Java 7. You probably have 1.6 or 1.8. Export JAVA_HOME in order to user proper Java version: ``` export JAVA_HOME=`/usr/libexec/java_home -v 1.7` export PATH=${JAVA_HOME}/bin:$PATH ``` #### Building After cloning the project, you can build it from source with this command: ``` mvn package ``` ### 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 ``` 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 generate - Generate code with chosen lang SYNOPSIS swagger generate [(-a | --auth )] [(-c | --config )] [-D ] (-i | --input-spec ) (-l | --lang ) [(-o | --output )] [(-t