Matchup

NSwag vs OpenAPI Generator

The usual choice for .NET teams generating clients from an OpenAPI description. NSwag is built for .NET: it writes C# and TypeScript clients and can produce the description from your ASP.NET Core controllers in the same build. OpenAPI Generator covers far more languages, with a separate generator for each. Both are free and open source.

vs
Criteria

Tick what matters. ×2 counts a criterion double.

Verdict

OpenAPI Generator wins, 11 to 9, narrowly, over NSwag.

NSwag 9/18 OpenAPI Generator 11/18

NSwag takes error handling. OpenAPI Generator takes language support and auth handling. Even on typing, retries and maintenance.

CriterionNSwagOpenAPI Generator
Language supportEdge: OpenAPI GeneratorPartial

Two client languages: C#, and TypeScript with templates for Fetch, Axios (preview), Angular, AngularJS, Aurelia and jQuery. Callers in any other language need another generator.

Check: NSwag README
Strong

It ships client generators for dozens of languages and frameworks. Quality and completeness vary by generator, so check the one you need.

Check: OpenAPI Generator: generators list
TypingEvenSolid

Typed C# DTOs and TypeScript classes or interfaces come from the schemas through NJsonSchema, which documents its handling of enums and inheritance. Check how oneOf comes through for your description.

Check: NSwag README
Solid

Typed models come from the schemas in your description. How well unions (oneOf), enums and nullables come through depends on the language's generator.

Check: OpenAPI Generator: generators list
Auth handlingEdge: OpenAPI GeneratorPartial

Security schemes don't become client configuration. You add the Authorization header yourself: an injected HttpClient or the PrepareRequest hook in C#, a base class with transformOptions in TypeScript.

Check: NSwag: TypeScript client generator
Solid

Security schemes in the description (API key, basic, bearer, OAuth) become configuration on the client. Token refresh is usually yours to build.

Check: OpenAPI Generator: generators list
RetriesEvenPartial

No retry logic is generated. The C# client takes an injected HttpClient, so retries come from whatever handlers you configure on it; in TypeScript you wrap the calls yourself.

Check: NSwag: C# client generator settings
Partial

Retry behaviour mostly comes from the HTTP library the generated client uses; you configure it, and it differs by generator.

Check: OpenAPI Generator: generators list
Error handlingEdge: NSwagSolid

Exception classes are generated by default and carry the status code, response body and headers; documented error responses with a schema come back as a typed result on the exception.

Check: NSwag: C# client generator settings
Partial

Most generators raise one generic API exception with the status code and body; typed error models vary by generator.

Check: OpenAPI Generator: generators list
MaintenanceEvenSolid

One .nswag configuration file regenerates the clients from the CLI, an npm package or an MSBuild target, and the same toolchain can produce the description from your ASP.NET Core controllers. Check its releases page for recent activity.

Check: NSwag: C# client generator
Solid

Regenerate from the description when the API changes. Custom templates and patches have to be carried forward across generator upgrades.

The verdict, and when to ignore it

OpenAPI Generator wins, 11 to 9, narrowly, over NSwag. NSwag takes error handling. OpenAPI Generator takes language support and auth handling. Even on typing, retries and maintenance.

Pick NSwag when

Your API is ASP.NET Core, your callers are C# services and a TypeScript front end, and you want the description and both clients from one .nswag file in your build.

NSwag on GitHub

Pick OpenAPI Generator when

Callers need languages beyond C# and TypeScript (Java, Go, Python, Kotlin, Swift), or you want one generator for every client. Check that its csharp and typescript generators fit your framework.

openapi-generator.tech