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.
Swagger Generators:
- ASP.NET Web API, WebApiToSwaggerGenerator
- Types from .NET assemblies AssemblyToSwaggerGenerator
Client Generators:
- TypeScript, SwaggerToTypeScriptGenerator
- CSharp, SwaggerToCSharpGenerator
Read more about the available Swagger and Client Generators
Ways to use the toolchain:
- In your C# code
- Via command line
- Generate code with T4 templates in Visual Studio
- Windows GUI NSwagStudio
Downloads and Build Artifacts (command line tool and NSwagStudio)
This project uses NJsonSchema for .NET for JSON Schema generation.
The following code shows how to generate C# client classes to call a web service:
var service = SwaggerService.FromJson("...");
var generator = new SwaggerToCSharpGenerator(service);
generator.Class = "MyClass";
generator.Namespace = "MyNamespace";
var code = generator.GenerateFile();