Repolode
swagger-api

swagger-api/swagger-codegen

Command-line tool that generates API client SDKs, server stubs and HTML docs from an OpenAPI/Swagger definition.

Stars
17,793
Forks
5,948
Open issues
3,442
Last commit
yesterday

What is it?

Swagger Codegen is a template-driven code generator that reads an OpenAPI or Swagger specification and produces API client libraries, server stubs and API documentation. It removes the need to hand-write request models and endpoint wrappers for each language a team uses.

The project supports a long list of targets, including clients for Java, C#, Go, Python, TypeScript, PHP, Swift, Kotlin, Rust and many others, plus server stubs for frameworks such as Spring, ASP.NET Core, Flask and Rails. Documentation can be produced as a static HTML file or as a dynamic single-page HTML app. Generation is run through a CLI JAR, Docker, or Maven and Gradle workflow integrations.

The project is split into 2.X and 3.X version lines with different Maven group IDs, and OpenAPI 3.0 is supported only in the 3.X line. Templates are customizable, so teams can adjust output or add their own targets.

Key features

  • 01Generates API clients in dozens of languages and frameworks from OpenAPI or Swagger specs.
  • 02Produces server stubs for frameworks such as Spring, ASP.NET Core, Flask and Rails.
  • 03Generates static or dynamic HTML API documentation.
  • 04Templates can be customized to change output or add new generators.
  • 05Runs from a CLI, Docker, or Maven and Gradle workflows.

Use cases

  • Generating a typed SDK for an internal REST API consumed by multiple client teams.
  • Scaffolding server stubs from a spec-first API design.
  • Publishing HTML reference documentation from an OpenAPI file.
  • Building a sample petstore client to explore generated code structure.

Quick start

  1. 1

    Clone the repository

    git clone https://github.com/swagger-api/swagger-codegen
  2. 2

    Enter the project directory

    cd swagger-codegen
  3. 3

    Build the project with Maven

    mvn clean package
  4. 4

    Generate a PHP client from the Petstore spec

    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

Things to know

  • You must build from source with Java and Maven, which adds setup effort.
  • Versions 2.X and 3.X are maintained separately with different group IDs, so check which line you need.

Topics

FAQ

What is swagger-codegen?
Command-line tool that generates API client SDKs, server stubs and HTML docs from an OpenAPI/Swagger definition. Swagger Codegen is a template-driven code generator that reads an OpenAPI or Swagger specification and produces API client libraries, server stubs and API documentation. It removes the need to hand-write request models and endpoint wrappers for each language a team uses.
Is swagger-codegen free to use? What license does it have?
swagger-codegen is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is swagger-codegen still maintained?
Actively maintained. The last commit to swagger-codegen was on Oct 22, 2026.
What can I use swagger-codegen for?
Generating a typed SDK for an internal REST API consumed by multiple client teams. Scaffolding server stubs from a spec-first API design. Publishing HTML reference documentation from an OpenAPI file. Building a sample petstore client to explore generated code structure.
How do I install swagger-codegen?
Clone the repository: git clone https://github.com/swagger-api/swagger-codegen Enter the project directory: cd swagger-codegen Build the project with Maven: mvn clean package Generate a PHP client from the Petstore spec: 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
Where can I get swagger-codegen?
The source code and installation instructions are on GitHub: https://github.com/swagger-api/swagger-codegen

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects