Repolode
RicoSuter

RicoSuter/NSwag

A Swagger/OpenAPI toolchain for .NET and ASP.NET Core that generates API specs from controllers and C# or TypeScript clients from specs.

Stars
7,368
Forks
1,363
Open issues
2,068
Last commit
2 months ago

What is it?

NSwag is a toolchain for working with OpenAPI (Swagger) specifications in .NET and TypeScript projects. It can generate OpenAPI 2.0 and 3.0 documents from ASP.NET Web API and ASP.NET Core controllers, and serve them through middleware alongside Swagger UI or ReDoc.

In the other direction, it reads an existing OpenAPI specification and generates C# or TypeScript client code. TypeScript output supports several targets, including Angular, AngularJS, Aurelia, jQuery, Axios, and the browser Fetch API. The project uses NJsonSchema for JSON Schema handling and type generation.

NSwag can be run from a command line tool (distributed as a NuGet tool or an npm package), from MSBuild targets, or from the Windows GUI NSwagStudio. Configuration is stored in a JSON file.

Key features

  • 01Generates Swagger 2.0 and OpenAPI 3.0 documents from ASP.NET (Core) controllers.
  • 02Serves API specs with Swagger UI or ReDoc via middleware.
  • 03Generates C# and TypeScript clients from OpenAPI specifications.
  • 04Supports multiple TypeScript HTTP templates, including Angular, Fetch, and Axios.
  • 05Runs from CLI, MSBuild, or the NSwagStudio Windows app.

Use cases

  • Documenting an existing ASP.NET Core Web API with OpenAPI and Swagger UI.
  • Generating a typed C# client to call a REST service from another .NET project.
  • Producing an Angular or Fetch-based TypeScript client from a backend API spec.
  • Automating client code generation in a build pipeline with MSBuild or the CLI.

Quick start

  1. 1

    Install the NSwag NuGet packages in your ASP.NET Core project (for example NSwag.AspNetCore)

  2. 2

    Register NSwag in Startup.cs with AddOpenApiDocument, then call UseOpenApi and UseSwaggerUi

  3. 3

    Generate C# or TypeScript clients from an OpenAPI file using the code samples in the README or the NSwag CLI

Things to know

  • NSwagStudio is a Windows-only desktop application.
  • Command-line use on Mac and Linux depends on Mono or the .NET Core console binary.
  • The ASP.NET Core OpenAPI generator is marked experimental in the README.

Topics

FAQ

What is NSwag?
A Swagger/OpenAPI toolchain for .NET and ASP.NET Core that generates API specs from controllers and C# or TypeScript clients from specs. NSwag is a toolchain for working with OpenAPI (Swagger) specifications in .NET and TypeScript projects. It can generate OpenAPI 2.0 and 3.0 documents from ASP.NET Web API and ASP.NET Core controllers, and serve them through middleware alongside Swagger UI or ReDoc.
Is NSwag free to use? What license does it have?
NSwag is open source under the MIT license. Check the license terms before using it in commercial products.
Is NSwag still maintained?
Updated within 6 months. The last commit to NSwag was on Sep 7, 2026.
What can I use NSwag for?
Documenting an existing ASP.NET Core Web API with OpenAPI and Swagger UI. Generating a typed C# client to call a REST service from another .NET project. Producing an Angular or Fetch-based TypeScript client from a backend API spec. Automating client code generation in a build pipeline with MSBuild or the CLI.
How do I install NSwag?
Install the NSwag NuGet packages in your ASP.NET Core project (for example NSwag.AspNetCore) Register NSwag in Startup.cs with AddOpenApiDocument, then call UseOpenApi and UseSwaggerUi Generate C# or TypeScript clients from an OpenAPI file using the code samples in the README or the NSwag CLI
Where can I get NSwag?
The source code and installation instructions are on GitHub: https://github.com/RicoSuter/NSwag

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

Related projects