Questions tagged [nswag]

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 generate Swagger specifications from existing Web API controllers and client code from these Swagger specifications.

The project combines the functionality of Swashbuckle (Swagger generation) and AutoRest (client generation) in one tool chain. This way a lot of incompatibilites can be avoided and features which are not well described by the Swagger specification or JSON Schema are better supported (e.g. inheritance, enum and reference handling). The NSwag project heavily uses NJsonSchema for .NET for JSON Schema handling and C#/TypeScript class/interface generation.

http://NSwag.org

414 questions
9
votes
1 answer

Generate NSwag client as part of the build

I have a project that uses NSwag to generate a client and the contracts from a swagger file. I don't want these generated files to be tracked by git, so that when the project is built on the build server, it generates them as part of the build. I've…
Tom
  • 1,561
  • 4
  • 20
  • 29
9
votes
1 answer

NSwag: How do you Use Custom Value Object Types in C# -> Swagger -> C# client?

I have an API that uses Noda Time types in both input and output. The types are serialized to strings in the JSON using the default Noda Time serialization format (which basically is the ISO-8601 format). I have an object looking something like…
Mikkel R. Lund
  • 2,336
  • 1
  • 31
  • 44
9
votes
0 answers

Swagger, NswagStudio, c#, Required = Newtonsoft.Json.Required.DisallowNull, how to handle

Given: api that i have limited influence to in terms of changing, built on net core 2.2. Standart netCore swagger used. Some classes of DTO have fields in it marked with [System.ComponentModel.DataAnnotations.Required] But for some reasons (which…
Andrey Stepanov
  • 311
  • 2
  • 11
8
votes
1 answer

ASP.NET core: NSwag vs. Swashbuckle

we're currently using Swashbuckle.AspNetCore for API documentation purpose, but when it comes to generation of client-side models (Typescript) it seems there is a major drawback of it. As a sample, I enhanced the known ASP.NET default project…
clemensoe
  • 312
  • 2
  • 9
8
votes
0 answers

How to specify base interface with net5 OpenAPI support

I am trying to adapt a project to .net5 and want to use the new feature of adding an OpenAPI service reference. As far as I understand it, NSwag will be used to generate the client. I already used NSwag for this purpose in the past and I could use…
Daniel Fink
  • 173
  • 1
  • 8
8
votes
1 answer

Is it possible in NSwag to generate just C# client interfaces and annotate their methods with some custom attributes?

I am using NSwag to generate C# rest client for my asp.net core web API. At the moment, I just need to generate the client interfaces and not the classes themselves. I tried the following settings to generate just C# client interfaces but it does…
Sayari
  • 103
  • 5
8
votes
1 answer

How can i disable / handle init, toJSON

I've created a .NET core 2.2 webapi, and using swagger / nswag to generate the API for my React / typescript application. When I try to set up a new object I get a ts(2739) message: Type '{ firstName: string; lastName: string; }' is missing the…
RMCS
  • 383
  • 3
  • 17
7
votes
0 answers

How to enable the "text/plain" content type in the documentation generated by NSwag?

I'm trying to create a controller in an AspNetCore 3.1 API. c #, with the help of "NSwag.AspNetCore" 13.1.3. The purpose of this controller is to receive and return plain text (not json). The controller code looks like…
Silvair L. Soares
  • 1,018
  • 12
  • 28
7
votes
0 answers

NSwag generating primitive fields as Nullable

I have a RESTful WebAPI 2 service in C# and I am using swagger as API descriptor. Now, on the client side I am using NSwag which can be found here to generate client side code: https://github.com/RSuter/NSwag Now, I have been using nSwag for more…
Lost
  • 12,007
  • 32
  • 121
  • 193
6
votes
0 answers

Path settings in OpenApiReference (Nswag/Visual Studio) in csproj file (msbuild)

I reference an OpenAPI service using the "Connected Services" feature in Visual Studio (2002 Prev 5, but same behavior in VS 2019). This tool is based on NSwag. The docs say that I can apply all settings from Nswag in certain elements of…
Joerg Krause
  • 1,759
  • 1
  • 16
  • 27
6
votes
2 answers

Using NSwag to generate a C# client incorrectly creates 2x partial classes with the same name, in the same file

I'm trying to generate an NSwag C# Client, from an OpenAPI json file. When I do this, I do get a client file generated, but it doesn't compile. It has created 2x partial classes in the same .cs file. Now, if I change one of these class names to…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
6
votes
3 answers

How to have different names for my API DTO's (based on the generator) with Nswag?

I have a .NET 5.0 ASP.NET Core project and I am using Nswag to generate an API client. Let's say I have the following API model: public class GetFooListResponseModel { public string Bar { get; set; } } What I would like is 2 things. Let's start…
S. ten Brinke
  • 2,557
  • 4
  • 25
  • 50
6
votes
2 answers

iServiceCollection' does not contain a definition for 'addVersionedApiExplorer'

In an Asp.Net Core v3.1 api, Swagger v3.0, the Swagger UI cannot load API definitions when I have declared multiple versions. Edit: Also from NuGet: Mcrosoft.AspNetCore.Mvc.Versioning v4.1.1 NSwag.AspNetCore v13.7.0 Following the documentation of…
Lupa
  • 586
  • 1
  • 8
  • 22
6
votes
3 answers

How to handle FileResponse return type of Nswag methods

I am using Nswag to generate client library to consume an API created from .NET Core Application. Currently I am using actions that returns IActionResult to benefit from methods such as return NotFound(); and return Ok(objectValue); If the return…
Endri
  • 714
  • 13
  • 34
6
votes
3 answers

NSwag - Separate file generation

I'm using NSwag to generate my TypeScript client (Angular format), but I'm having problems with implementing Bearer token authentication because of circular dependencies. My user service needs to import the TS client to use the token DTOs and my TS…
André Dias
  • 163
  • 1
  • 12
1
2
3
27 28