Nswag: Controller Code does not compile .NET Core 2.1 / ASP.NET Core 2.1.1

Created on 29 Aug 2018  路  3Comments  路  Source: RicoSuter/NSwag

Hello,

There is several issues in compiling Controller code for .NET Core 2.1 / ASP.NET Core 2.1.1 - I cannot compile the code. Is it my mistake?

  • Microsoft.AspNetCore.Mvc.RoutePrefix attribute does not exist
  • (Check "Generate optional parameters" + Check "Add cancellation token"): optional parameters cannot be specified like that before the mandatory cancellation token
  • (Check "Wrap success responses to allow full response access"): Request.CreateResponse (no overload takes 2 arguments)

Best wishes!

help wanted NSwag.CodeGeneration.CSharp (Controllers) enhancement

Most helpful comment

I fixed compile time errors overriding the liquid template. Tomorrow I will check if it works functionality-wise and create a PR to fix the issues.

All 3 comments

I fixed compile time errors overriding the liquid template. Tomorrow I will check if it works functionality-wise and create a PR to fix the issues.

Is there a work-around until the CreateResponse issue is fixed?

  • The RoutePrefix issue can be resolved by using the ASP.NET Core Route attribute
  • The cancellation token issue can be fixed by appending "= default(CancellationToken)" to the cancellation token definition
  • The CreateResponse method was completely removed in ASP.NET Core. You'll need to use the StatusCode() method of the controller to create an IActionResult, and work from there

I started to rewrite the template but saw that it's not about simply fixing this issues. It also does not generate model code and it misses verification code. Overall impression is that NSwag is more thought to generate Swagger specs from .NET Code, but not to generate (powerful) .NET Code from Swagger.

Thats the reason why I moved to OpenAPI-Generator for now. I want to have spec first, code second. Sorry, I unfortunately do not have the resources right now to fix the issues for NSwag.

Was this page helpful?
0 / 5 - 0 ratings