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
0
votes
0 answers

How to remove Extra Required attribute added by NSwag

I have some code like below: namespace BSN.Commons.Responses { // // Summary: // Generic response type for command/query services to return the results. [DataContract] public class Response where T : class { …
sorosh_sabz
  • 2,356
  • 2
  • 32
  • 53
0
votes
0 answers

NSwag.MSBuild is timing out when added as target to a .csproj target

I'm teaching myself the basics of NSwag right now. With the goal to standardize & automate my company's API Clients. During this I found the NSwag.MSBuild which seemed perfect for my desires to build the API Client during our build pipelines. …
Curtis
  • 1
  • 3
0
votes
0 answers

Nswag: Is there a way to generate only non-primitives and nullable primitives as nullable?

I'm looking for a way to have nswag generate a C# client for me that generates nullables for nullable primitives and all non-primitives, but not for non-nullable primitives. Say I have a C# object such as public bool NonNullableBool { get; set;…
0
votes
1 answer

How to generate TypeScript client using NSwag in form of named properties?

We generate TypeScript client from swagger interface using NSwag. The generated client looks like following: client.EndPointFoo(arg1, arg2, arg3, ...) We deal with issues that NSWag change order of arugments in case of some changes in Swagger…
Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
0
votes
1 answer

SDK Resolver Error: Could not resolve "Microsoft.NET.Sdk.Web"

I am getting the following errors on NSwag Studio since a week. I had done a VS 2022 update recently and the current version is 17.5.5. I tried reverting to the previous version but it still doesn't help. I get this error while trying to generate…
codredd
  • 21
  • 3
0
votes
1 answer

ModelState validation in auto-generated controllers

I want to return 400 Bad request when ModelState.IsValid is false, i.e., when a string is not mapped correctly to an appropriate enum. (For example when calling GET v1/abc/def/gamma for API GET v1/abc/def/{id} where id is an enum with values alpha &…
12oClock
  • 1
  • 4
0
votes
1 answer

Nswag studio is unable to handle a JSON body with an array

I am using NSwag Studio to generate a C# client for an external Swagger API that I need to interact with. One of the properties on an API call that I am attempting to execute is a typed array. From the specification.json: "segmentValues": { …
0
votes
1 answer

config.json and using values in app.module.ts providers

Currently, we are building our angular (v15) application once for each environment we deploy to, since we are using the environment.ts files to handle variable transforms. I would like to get us to a flow more similar to our backend, AspNetcore,…
Delubear
  • 56
  • 5
0
votes
0 answers

Nswag IOperationProccessor alternative at runtime

I have created a method that implements IOperationProcessor looking for to hide operations depending of the permissions of a user. In my implementation with Nswag , the IOperationProcessor method is been only called at compilation time, when i…
Nando
  • 11
  • 5
0
votes
0 answers

Generate typescript @summary from [annotation] in dotnet

I have a set of DTOs, that can be either submitted or received by the client in an api call. The way, that we synchronize between client<-> server DTOs is using NSwag, which generates a client.ts file, containing all of the types and actions. It…
alx
  • 1
  • 1
0
votes
1 answer

Sending date from angular frontend to aspnetcore backend - timezone troubles

I have a problem sending dates via a NSwag generated typescript client to an aspnetcore webapi. The generated code is: getExchangeRate(from: string, to: string, date: Date): Observable { let url_ = this.baseUrl +…
0
votes
0 answers

OpenAPI generator fails to type hint a file from NSwag

I have a backend service written in .NET Core and I use NSwag to generate a Swagger client. My client app, which is written in TypeScript, uses this Swagger to generate code for the requests. This works perfectly fine except for files. I have one…
anthino12
  • 770
  • 1
  • 6
  • 29
0
votes
1 answer

Cannot send file content to an API with Post method code generated with nswag from swagger.json

Exception occured on line : (after PrepareRequest) var response_ = await client_.SendAsync(request_, System.Net.Http.HttpRequestException: 'Error while copying content to a stream.' IOException: Unable to write data to the transport connection: An…
0
votes
1 answer

Generating a TypeScript client for React components embedded in an ASP.NET MVC web app

The question: is it possible to automatically generate a TypeScript client that defines data transfer between a React component and an ASP.NET MVC controller? The context is: we have a TypeScript React app that consumes an ASP.NET Core Web API and…
Dave
  • 457
  • 4
  • 15
0
votes
1 answer

How to generate the openapi.json with nswag

I am using nswag to generate the swagger. However the openapi json file is only in memory, you can only access it by starting the application and navigate to the link swagger/v1/swagger.json. I want the json file to be generated and save physically…