Closed JonnyWideFoot closed 7 months ago
FYI. This is fixed in DotSwashbuckle 3.0.6+
To make issue tracking a bit less overwhelming for the new maintainers (see #2778), I've created a new tracking issue to roll-up various nullability issues here: #2793.
We'll refer back to this issue from there and include it as part of resolving that issue, but I'm going to close this one to help prune the backlog.
Problem Statment
I have the following response type in a C# dotnet 7.0 project, withenable in the csproj:
By default, swagger is generating this type as:
Which is interpreted by my openAPI generator as:
This is not what I want, as nullability does not match the C# type.
If I enable 'SupportNonNullableReferenceTypes':
Then the nullability is corrected in the swagger json file:
However this generates with "id?", not "id":
This is because the property is not listed in the required array for the type, however I think this behaviour is undesirable, as a non-bullable type should be required by definition.
I have made a filter which resolves this for me. See attached code below. I was wondering if you agree that the default behaviour should be that non-nullable types are in the reqired list required by definition?
Usage:
Results in:
And generates a client thus:
Bug or intended behaviour?
Sample Code
Filter
Helpers
Tests