-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Required and nullable properties are not nullable in the OpenAPI JSON #2877
Comments
Thanks for the report - this looks like an oversight in the changes for |
I've updated the issue description so that |
@cremor If you can validate the changes from #2879 fix your issue using a CI version from our MyGet feed, we can look at shipping a fix tomorrow if it's all good. |
I can check it tomorrow around 7:00 CEST. |
Thanks! |
I can confirm that this is fixed in 6.6.2-preview.334, thanks! |
@martincostello I know that the 6.6.2 milestone got much bigger since you wrote this, but what's the current plan for shipping it? If you need help, is there a way I can? I already reviewed the two open PRs in the milestone. |
I'm waiting for reviews from one of the other contributors with write access. Once all the PRs associated with the milestone are merged (there's 2), I'll do the release. |
Could you create a new issue please with a reproducible code sample, and then we can look into that. |
You should check the OpenAPI JSON file that Swashbuckle creates, not some generated code that gets generated from another library. If it's nullable (and required) in the OpenAPI JSON then it's the fault of the code generator. |
Describe the bug
Properties with the
required
modifier are always generated as not nullable (and in the case of strings also withminLength: 1
), even if they are nullable.Expected behavior
Nullable properties should be nullable in the OpenAPI JSON.
Example:
Actual behavior
Nullable properties are always not-nullable in the OpenAPI JSON if they are also
required
.Example:
Steps to reproduce
WeatherForecast
model like shown below.return null;
so the project compiles.Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
6.6.1
.NET Version
8.0.204
Anything else?
This is a new problem in Swashbuckle 6.6.1 (6.6.0). In 6.5.0 the
required
keyword didn't have any effect.I assume this was caused by @keahpeters in #2810
required
doesn't mean that a not-null value is required. It just means that any value (which can benull
) is required. In other words: It just means that the request body needs to contain the property.Related to #2036, but that issue has so many comments already that I'm not sure if it requests something more than I do here.
Should be added to #2793
The text was updated successfully, but these errors were encountered: