NSwag is a Swagger 2.0 API toolchain for .NET, TypeScript and other platforms, written in C#. The Swagger specification uses JSON and JSON Schema to describe a RESTful web API. The project provides tools to automatically generate client code from these Swagger specifications and integrate this generation into existing processes.
Ways to use the toolchain:
- Simple to use Windows GUI, NSwagStudio
- In your C# code, via NuGet
- Via command line (Windows, Mac and Linux support through Mono)
- Generate code with T4 templates in Visual Studio
Swagger Generators:
- ASP.NET Web API
- Types from .NET assemblies, AssemblyTypeToSwaggerGenerator
Client Generators:
- CSharp, SwaggerToCSharpGenerator
- With INotifyPropertyChanged supporting DTOs
- TypeScript, SwaggerToTypeScriptGenerator
- Available templates/supported libraries:
- JQuery with Callbacks,
JQueryCallbacks
- JQuery with Q promises
JQueryQPromises
- AngularJS using $http,
AngularJS
- JQuery with Callbacks,
- Available templates/supported libraries:
Downloads
- Download latest NSwagStudio MSI installer (Windows Desktop application)
- Download latest NSwag command line tools and NSwagStudio as ZIP archive
- Download latest Build Artifacts from AppVeyor (command line tools and NSwagStudio binaries)
This project uses NJsonSchema for .NET for JSON Schema, C# and TypeScript class/interface generation.
The following code shows how to read a Swagger specification and generate C# client classes to call the described web services:
var service = SwaggerService.FromJson("...");
var settings = new SwaggerToCSharpGeneratorSettings
{
ClassName = "MyClass",
Namespace = "MyNamespace"
};
var generator = new SwaggerToCSharpGenerator(service, settings);
var code = generator.GenerateFile();
Check out the project Wiki for more information.
The generators can be used in a confortable and simple Windows GUI called NSwagStudio: