Skip to content
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

Support the required keyword in the same way as RequiredAttribute #2764

Closed
AntiGuideAkquinet opened this issue Feb 2, 2024 · 4 comments · Fixed by #2810
Closed

Support the required keyword in the same way as RequiredAttribute #2764

AntiGuideAkquinet opened this issue Feb 2, 2024 · 4 comments · Fixed by #2810

Comments

@AntiGuideAkquinet
Copy link
Contributor

AntiGuideAkquinet commented Feb 2, 2024

When using .NETs required keyword, the properties that it is used on do not get marked as required in SwaggerGen. I set up a project to reproduce the issue. When adding the RequiredAttribute to the property, the result changes to the expected behavior.

I assume that this line could fix the problem if it checked for RequiredMemberAttribute too.

Thank you for investigating!

Version: 6.5.0
C# 11/.NET 7 and up
SwashbuckleReproduction.zip

@KRSogaard
Copy link

+1 this is causing a lot of problem in API communication with frontend team members

@Havunen
Copy link

Havunen commented Feb 17, 2024

This functionality has been implemented in DotSwashbuckle v3.0.1
Havunen@2871109
https://www.nuget.org/packages/DotSwashbuckle.AspNetCore

Havunen added a commit to Havunen/DotSwashbuckle that referenced this issue Feb 18, 2024
@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Apr 13, 2024
@martincostello martincostello removed the help-wanted A change up for grabs for contributions from the community label Apr 17, 2024
@mattiasnordqvist
Copy link

mattiasnordqvist commented May 16, 2024

Why did you do this? Required-keyword in C# has nothing to do with nullability. It is there to enforce initialization of properties in constructor or constructor-initializers. It is perfectly fine in C# to declare a property as a required nullable int like this: required int? { get; set; }

@martincostello
Copy link
Collaborator

See #2879.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants