[NSwagStudio] Nullable Timespan in ASP web api 2 generates different C# method signature when using Output type of "OpenApi3" vs "Swagger2"
See original GitHub issueHey, I’m using NSwagStudio x64 v11.19.2.0 With below ASP web api 2 controller:
[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
[HttpPut, Route("{id}/expiry")]
[SwaggerResponse(200, typeof(bool))]
public async Task<IHttpActionResult> PutExpiry([FromUri] string id, [FromBody] TimeSpan? expiry)
{
await Task.Yield();
var success = true;
return Ok(success);
}
}
public class ValueDto
{
[Required]
public string Id { get; set; }
}
In NSwag Studio I get different C# client when selecting Swagger2 vs OpenApi3.
Swagger2:
public System.Threading.Tasks.Task<bool> PutExpiryAsync(string id, System.TimeSpan? expiry)
OpenApi3:
public System.Threading.Tasks.Task<bool> PutExpiryAsync(string id, System.TimeSpan expiry)
Notice in OpenApi3 the System.TimeSpan is not nullable. For now I manually change the generated code to ‘TimeSpan?’, but fear another dev might overwrite it in future when they re-generate client.
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (10 by maintainers)
Top Results From Across the Web
[NSwagStudio] Nullable Timespan in ASP web api 2 ...
[NSwagStudio] Nullable Timespan in ASP web api 2 generates different C# method signature when using Output type of "OpenApi3" vs "Swagger2" ...
Read more >Get started with NSwag and ASP.NET Core
Learn how to use NSwag to generate documentation and help pages for an ASP.NET Core web API.
Read more >asp.net core - Why do NSwag fail on my computer and not ...
I'm working on a large C# Asp.NetCore 3.1 project where we uses Nswag to generate swagger.json and a C# ProxyClient for our API....
Read more >Using OpenApiReference To Generate Open API Client ...
Specifies whether to generate contracts output (interface and models in a separate file set with the ContractsOutput parameter).
Read more >Swashbuckle vs. NSwag in ASP.NET Core
In this article, we will explore the two popular libraries for generating OpenAPI documentation in C#: Swashbuckle and NSwag.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve added AllowNullableBodyParameters setting (default: true) - now nullable should be correctly handled in OpenAPI 3 (without changing anything). In the next major release (v12) the default will be set to false to reflect the current implementation of ASP.NET Core 2+… Keeping default true to not break anyone now.
Just verified 😃 works on x64 11.20.0.0.