question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[NSwagStudio] Nullable Timespan in ASP web api 2 generates different C# method signature when using Output type of "OpenApi3" vs "Swagger2"

See original GitHub issue

Hey, 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:closed
  • Created 5 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
RicoSutercommented, Sep 28, 2018

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.

1reaction
G4rcecommented, Oct 1, 2018

Just verified 😃 works on x64 11.20.0.0.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found