nswag

Create one code client / flatten controllers with NSwag and AutoREST

巧了我就是萌 提交于 2021-02-08 10:55:49
问题 I'm trying to create a code wrapper for an api with NSwag and Autorest. Previously I was using Swashbuckle to generate the swagger file. It generated the swagger file with operationIds in the format actionMethod . This resulted in Autorest generating a code client that was 1-deep. All of the actions were on the top-level class. For various reasons, I needed to change swagger generation to NSwag. This generates operationIds in the format controller_actionMethod . This results in AutoRest

How to order/sort paths in NSwag swagger.json by controller name

有些话、适合烂在心里 提交于 2021-01-27 20:46:46
问题 I am using NSwag to generate swagger for my .NET Core api and everything works great, except the fact that paths are rendered in order that reflection seems to pickup Controllers from project. So if I do have hierarchy - some controllers at root level ( Controllers folder) and some in subfolder ( Controllers\Subfolder folder) then the order gets messed up. Is it possible to somehow tell NSwag to generate resulting swagger.json showing operations in alphabetical order? 回答1: There is option

What is the correct way to download a file via the NSwag Code Generator (angular 2 typescript)

孤者浪人 提交于 2020-08-22 04:36:06
问题 I try to download a file via an angular 2 typescript client. The link generated in Swagger UI works fine, but the generated typescript client does not. The controller looks like this: [HttpGet("export")] [SwaggerResponse((int) HttpStatusCode.OK, Type = typeof(FileContentResult))] [ProducesResponseType(typeof(FileResult), (int) HttpStatusCode.OK)] [Produces("text/csv")] public virtual FileResult Export(int Id, string fileType, CsvFormat format, bool includeHeader) { . . . FileStreamResult file

Extension point or access to OpenApiDocument from Liquid Template

ぃ、小莉子 提交于 2020-04-11 06:57:07
问题 We have Specification Extensions (i.e. x-isPrimaryKey ) in our generated OpenApiDocument and need to add them as ClassDecorators to our Angular models. e.g. We communicate if is Pk, Fk and property level permissions. I am successfully overriding the File.liquid to customize the generated models. I have explored the TypeScriptFileTemplateModel but _document is private . Any help with discoverability of Template Variables for .Liquid files is appreciated. Specifically, is there an extension

How to upload data + multiple files from Angular to .net core Web Api

随声附和 提交于 2020-01-30 06:43:05
问题 My server uses .Net Core 2.1.402 Here is my C# class: public class SampleDetailsDto { public Guid Id{ get; set; } public string Text { get; set; } public IEnumerable<string> ImageUrls { get; set; } public IFormCollection Images { get; set; } } Here is my C# Controller [HttpPut] [Route("{id:guid}")] public async Task<IActionResult> UpdateAsync([FromRoute]Guid id, [FromForm] SampleDetailsDtodto) { Console.WriteLine(dto.Text); Console.WriteLine(dto.Images.Length); return OK(); } I use nswag to

How to include Http request method name in client method names generated with NSwag

不打扰是莪最后的温柔 提交于 2020-01-03 03:20:07
问题 When I generate a C# client for an API using NSwag, where the API includes endpoints that can be used with multiple Http request types (e.g. POST, GET) the client generates a method for each request with the same base name, plus a number. E.g. Using this API: https://api.premiumfunding.net.au/assets/scripts/swagger/v1/swagger.json The schema contains an endpoint /contract that supports GET and POST requests, and an endpoint /contract/{ID} that supports GET , POST and DELETE requests. The

How to use a custom model binder with Swashbuckle, Swagger and NSwag?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 08:46:55
问题 I have an ASP.NET Core Web API that contains the following endpoint. [HttpGet] [Route("models/{ids}")] [Produces(typeof(IEnumerable<Model>))] public IActionResult Get ( [ModelBinder(typeof(CsvModelBinder<string>))] IEnumerable<string> ids ) { // Get models return Ok(models); } This endpoint takes a CSV list of Ids (e.g. /models/a,b,c ) and returns a JSON array of the corresponding Model objects. CsvModelBinder<string> is a custom implementation of IModelBinder I wrote that splits the CSV list

Implement JwtBearer Authentication in NSwag SwaggerUi

爷,独闯天下 提交于 2019-12-10 20:52:02
问题 In my asp.net core 2.0 solution I want to add Azure AD authentication. With the Azure AD templates inside of VS 2017 you either get JWTBearer authentication-implementation or OpenIdConnect implementation. Open Id also has the reputation of being more secure than OAuth. How can I use Open ID / JWT with the Swagger Ui, provided by NSwag? My current workaround would be to allow both OAuth and Open Id, but I need to implement that myself and there is almost no documentation on the new 2.0 APIs.

How to include Http request method name in client method names generated with NSwag

ぐ巨炮叔叔 提交于 2019-12-06 15:27:01
When I generate a C# client for an API using NSwag, where the API includes endpoints that can be used with multiple Http request types (e.g. POST, GET) the client generates a method for each request with the same base name, plus a number. E.g. Using this API: https://api.premiumfunding.net.au/assets/scripts/swagger/v1/swagger.json The schema contains an endpoint /contract that supports GET and POST requests, and an endpoint /contract/{ID} that supports GET , POST and DELETE requests. The generated client has methods: ContractAsync for GET requests without ID Contract2Async for POST requests