/NSwag

NSwag: The Swagger API toolchain for .NET

Primary LanguageC#Microsoft Public LicenseMS-PL

NSwag: The Swagger API toolchain for .NET

Build status NuGet Version

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:

Swagger Generators:

Client Generators:

Downloads

This project uses NJsonSchema for .NET for JSON Schema, C# and TypeScript class/interface generation.

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 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.

NSwagStudio

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