The Swagger/OpenAPI toolchain for .NET, Web API and TypeScript.
Switch branches/tags
NSwag-Build-1032 NSwag-Build-1031 NSwag-Build-1029 NSwag-Build-1027 NSwag-Build-1026 NSwag-Build-1025 NSwag-Build-1024 NSwag-Build-1023 NSwag-Build-1022 NSwag-Build-1021 NSwag-Build-1020 NSwag-Build-1019 NSwag-Build-1018 NSwag-Build-1017 NSwag-Build-1016 NSwag-Build-1015 NSwag-Build-1013 NSwag-Build-1009 NSwag-Build-1008 NSwag-Build-1007 NSwag-Build-1006 NSwag-Build-1005 NSwag-Build-1004 NSwag-Build-1003 NSwag-Build-1002 NSwag-Build-1001 NSwag-Build-1000 NSwag-Build-997 NSwag-Build-996 NSwag-Build-995 NSwag-Build-994 NSwag-Build-993 NSwag-Build-992 NSwag-Build-991 NSwag-Build-990 NSwag-Build-989 NSwag-Build-988 NSwag-Build-987 NSwag-Build-986 NSwag-Build-985 NSwag-Build-984 NSwag-Build-982 NSwag-Build-981 NSwag-Build-980 NSwag-Build-979 NSwag-Build-978 NSwag-Build-977 NSwag-Build-976 NSwag-Build-975 NSwag-Build-973 NSwag-Build-972 NSwag-Build-971 NSwag-Build-970 NSwag-Build-969 NSwag-Build-968 NSwag-Build-967 NSwag-Build-962 NSwag-Build-961 NSwag-Build-960 NSwag-Build-958 NSwag-Build-956 NSwag-Build-955 NSwag-Build-950 NSwag-Build-947 NSwag-Build-937 NSwag-Build-936 NSwag-Build-932 NSwag-Build-931 NSwag-Build-929 NSwag-Build-927 NSwag-Build-924 NSwag-Build-922 NSwag-Build-920 NSwag-Build-918 NSwag-Build-916 NSwag-Build-911 NSwag-Build-909 NSwag-Build-906 NSwag-Build-904 NSwag-Build-902 NSwag-Build-900 NSwag-Build-899 NSwag-Build-898 NSwag-Build-897 NSwag-Build-895 NSwag-Build-893 NSwag-Build-891 NSwag-Build-889 NSwag-Build-887 NSwag-Build-885 NSwag-Build-881 NSwag-Build-879 NSwag-Build-877 NSwag-Build-875 NSwag-Build-873 NSwag-Build-871 NSwag-Build-869 NSwag-Build-868 NSwag-Build-866 NSwag-Build-863
Nothing to show
Clone or download
Latest commit 87b6bd4 Nov 19, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets Updated NJS Nov 5, 2017
build Migrate to use Xunit (#1669) Nov 1, 2018
samples v12 (#1743) Nov 16, 2018
src Update NJS, closes #1751 Nov 19, 2018
.gitattributes nswag.js text eol=lf, #674 Mar 14, 2017
.gitignore Add TransformToExternalPath setting (#1728) Nov 12, 2018 Update Jul 10, 2017 Changed license to MIT Nov 30, 2016 Update license year Nov 5, 2018 Update Nov 16, 2018

NSwag: The Swagger/OpenAPI toolchain for .NET, Web API and TypeScript

NuGet Version npm Build status Build status MyGet CI Gitter StackOverflow Wiki

NSwag v12 released!

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 Swagger specification uses JSON and JSON Schema to describe a RESTful web API. The NSwag project provides tools to generate Swagger specifications from existing ASP.NET Web API controllers and client code from these Swagger specifications.

The project combines the functionality of Swashbuckle (Swagger generation) and AutoRest (client generation) in one toolchain. This way a lot of incompatibilites can be avoided and features which are not well described by the Swagger 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.


  • 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:


Swagger Generators:

Code Generators:

  • CSharp Client
    • SwaggerToCSharpClientGenerator
      • Generates C# clients from a Swagger 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
  • CSharp Controllers (contract first/schema first development)
  • TypeScript Client
    • SwaggerToTypeScriptClientGenerator
      • Generates TypeScript clients from a Swagger 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)


NPM Packages

  • NSwag: Command line tools (.NET and .NET Core) distributed as NPM package

NuGet Packages


  • NSwag.Core (.NET Standard 1.0 and .NET 4.5):
  • NSwag.Core.Yaml (.NET Standard 1.3 and .NET 4.5):
    • Extensions to read and write YAML Swagger specifications
  • NSwag.Annotations (.NET Standard 1.0 and .NET 4.5):
    • Attributes to decorate Web API controllers to control the Swagger generation

Swagger generation:

Code generation:



  • NSwag.AssemblyLoader (.NET Standard 1.6 and .NET 4.5.1):
    • Classes to load assemblies in an isolated AppDomain and generate Swagger specs from Web API controllers
  • NSwag.Commands (.NET Standard 1.6 and .NET 4.5.1+):
    • Commands for the command line tool implementations and UI
  • NSwag.MSBuild (MSBuild .targets):
    • Adds a .targets file to your Visual Studio project, so that you can run the NSwag command line tool in an MSBuild target, see MSBuild
  • NSwag.ConsoleCore (.NET Core 1.0, 1.1 and 2.0):
    • Command line tool for .NET Core (dotnet nswag)
  • NSwagStudio (Chocolatey, Windows):
    • Package to install the NSwagStudio and command line tools via Chocolatey

CI NuGet Feed:

The NuGet packages may require the Microsoft.NETCore.Portable.Compatibility package on .NET Core/UWP targets (if mscorlib is missing).


Usage in C#

The following code shows how to read a Swagger specification and generate C# client classes to call the described web services:

var swaggerSettings = new WebApiToSwaggerGeneratorSettings();
var swaggerGenerator = new WebApiToSwaggerGenerator(swaggerSettings);

var document = await swaggerGenerator.GenerateForControllerAsync<PersonsController>();

var clientSettings = new SwaggerToCSharpClientGeneratorSettings 
    ClassName = "MyClass",
    CSharpGeneratorSettings = 
        Namespace = "MyNamespace"
var clientGenerator = new SwaggerToCSharpClientGenerator(document, clientSettings);

var code = clientGenerator.GenerateFile();

Check out the project Wiki for more information.


The generators can be used in a comfortable and simple Windows GUI called NSwagStudio:


Companies or individuals which paid a substantial amount for implementing, fixing issues, support or sponsoring are listed below. Thank you for supporting this project! You can also become a sponsor via Patreon or by contacting Rico Suter