NSwag
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
Install / Use
/learn @RicoSuter/NSwagREADME
NSwag: The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript
NSwag | NJsonSchema | Apimundo | Namotion.Reflection
:point_right: Announcing Apimundo: An API documentation system based on NSwag and NJsonSchema :point_left:
NSwag is a Swagger/OpenAPI 2.0 and 3.0 toolchain for .NET, .NET Core, Web API, ASP.NET Core, TypeScript (jQuery, AngularJS, Angular 2+, Aurelia, KnockoutJS and more) and other platforms, written in C#. The OpenAPI/Swagger specification uses JSON and JSON Schema to describe a RESTful web API. The NSwag project provides tools to generate OpenAPI specifications from existing ASP.NET Web API controllers and client code from these OpenAPI specifications.
The project combines the functionality of Swashbuckle (OpenAPI/Swagger generation) and AutoRest (client generation) in one toolchain (these two libs are not needed). This way a lot of incompatibilites can be avoided and features which are not well described by the OpenAPI specification or JSON Schema are better supported (e.g. inheritance, enum and reference handling). The NSwag project heavily uses NJsonSchema for .NET for JSON Schema handling and C#/TypeScript class/interface generation.

The project is developed and maintained by Rico Suter and other contributors.
Features
- Generate Swagger 2.0 and OpenAPI 3.0 specifications from C# ASP.NET (Core) controllers
- Serve the specs via ASP.NET (Core) middleware, optionally with Swagger UI or ReDoc
- Generate C# or TypeScript clients/proxies from these specs
- Everything can be automated via CLI (distributed via NuGet tool or build target; or NPM)
- CLI configured via JSON file or NSwagStudio Windows UI
Ways to use the toolchain
- Simple to use Windows GUI, NSwagStudio
- By using the OpenAPI or OpenAPI UI OWIN and ASP.NET Core Middlewares (also serves the Swagger UI) (recommended)
- Via command line (Windows, Mac and Linux support through Mono or .NET Core console binary, also via NPM package)
- In your C# code, via NuGet
- In your MSBuild targets
- With ServiceProjectReference tags in your .csproj (preview)
- In your Azure V2 Functions (external project, might not use latest NSwag version)
Tutorials
- Add NSwag to your ASP.NET Core app
- Integrate the NSwag toolchain into your ASP.NET Web API project
- Generate an Angular TypeScript client from an existing ASP.NET Web API web assembly
- Video Tutorial: How to integrate NSwag into your ASP.NET Core Web API project (5 mins)
OpenAPI/Swagger Generators
- ASP.NET Web API assembly to OpenAPI (supports .NET Core)
- AspNetCoreOpenApiDocumentGenerator
- WebApiOpenApiDocumentGenerator
- Generates an OpenAPI specification for Web API controllers
- WebApiToOpenApiCommand
- Generates an OpenAPI specification for controllers in an external Web API assembly
- Also supports loading of .NET Core assemblies
- TypesToOpenApiCommand
- Generates an OpenAPI specification containing only types from .NET assemblies
Code Generators
- CSharp Client
- CSharpClientGenerator
- Generates C# clients from an OpenAPI specification
- Generates POCOs or classes implementing INotifyPropertyChanged supporting DTOs
- The generated clients can be used with full .NET, .NET Core, Xamarin and .NET Standard 1.4 in general
- CSharpClientGenerator
- CSharp Controllers (contract first/schema first development)
- CSharpControllerGenerator
- Generates Web API Controllers based on an OpenAPI specification (ASP.NET Web API and ASP.NET Core)
- CSharpControllerGenerator
- TypeScript Client
- TypeScriptClientGenerator
- Generates TypeScript clients from an OpenAPI specification
- Available templates/supported libraries:
- JQuery with Callbacks,
JQueryCallbacks - JQuery with promises
JQueryPromises - AngularJS using $http,
AngularJS - Angular (v2+) using the http service,
Angular - window.fetch API and ES6 promises,
Fetch(use this template in your React/Redux app) - Aurelia using the HttpClient from aurelia-fetch-client,
Aurelia(based on the Fetch template) Axios(preview)
- JQuery with Callbacks,
- TypeScriptClientGenerator
Downloads
- Download latest NSwagStudio MSI installer (NSwagStudio.msi) (Windows Desktop application)
- Download latest NSwag command line tools and NSwagStudio (NSwag.zip)
NPM Packages
- NSwag: Command line tools (.NET and .NET Core) distributed as NPM package
NuGet Packages
Specification
- NSwag.Core
- The OpenAPI/Swagger reader and writer classes, see OpenApiDocument (.NET Standard 1.0 / 2.0 and .NET 4.5)
- NSwag.Core.Yaml (.NET Standard 1.3 / 2.0 and .NET 4.5)
- Extensions to read and write YAML OpenAPI specifications
- NSwag.Annotations (.NET Standard 1.0 / 2.0 and .NET 4.5)
- Attributes to decorate Web API controllers to control the OpenAPI generation
OpenAPI generation
- NSwag.Generation (.NET Standard 1.0 / 2.0 and .NET 4.5)
- Classes to generate OpenAPI specifications
- NSwag.Generation.WebApi (.NET Standard 1.0 / 2.0 and .NET 4.5)
- Classes to generate OpenAPI specifications from Web API controllers, see WebApiOpenApiDocumentGenerator
- NSwag.Generation.AspNetCore (.NET Standard 1.6 / 2.0 and .NET 4.5.1)
- (Experimental) Classes to generate OpenAPI specifications from ASP.NET Core MVC controllers using the ApiExplorer
Code generation
- NSwag.CodeGeneration (.NET Standard 1.3 / 2.0 / .NET 4.5.1)
- Base classes to generate clients from OpenAPI specifications
- NSwag.CodeGeneration.CSharp (.NET Standard 1.3 and .NET 4.5.1)
- Classes to generate C# clients from OpenAPI specifications, see CSharpClientGenerator and [CSharpControllerGenerator](https://github.com/RicoSuter/NSw
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
109.5kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
100.3kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
