NSwag
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
A .NET toolset that reads your ASP.NET Core web API and automatically generates OpenAPI documentation and ready-to-use client code in C# or TypeScript, so you never write API client code by hand.
NSwag is a set of tools for .NET developers that automates two related tasks: describing how a web API works, and generating the code needed to call it from other applications.
When you build a web API in .NET or ASP.NET Core (Microsoft's frameworks for building websites and services), NSwag can read your existing code and produce an OpenAPI (formerly called Swagger) specification. This is a standardized document that describes every endpoint your API offers, what inputs each one expects, and what it returns. The document acts as a machine-readable contract that other tools can consume.
From that contract, NSwag generates ready-to-use client code in C# or TypeScript. Instead of writing by hand the code that calls your API from a website or another service, NSwag writes it for you. TypeScript clients are available for several popular frontend frameworks including Angular, AngularJS, React (via the Fetch template), and Aurelia. C# clients can be used in regular .NET apps, .NET Core, and Xamarin for mobile apps.
The toolchain runs several ways: through NSwagStudio, a Windows desktop application with a graphical interface; via a command line tool that works on Windows, Mac, and Linux; directly in C# code via NuGet packages; or as part of an automated build process through MSBuild targets. ASP.NET Core projects can add a middleware layer that serves the generated documentation page and an interactive browser UI alongside the running application, letting developers and consumers of the API explore available endpoints without reading code.
Where it fits
- Generate a TypeScript client for your React frontend from your ASP.NET Core API without writing any client code by hand
- Add an interactive API documentation browser to your .NET web app with a single middleware line so developers can explore endpoints in the browser
- Automate TypeScript and C# client regeneration as part of a CI/CD build pipeline using MSBuild targets so clients always match the API