domaindrivendev/Swashbuckle.AspNetCore

[Bug]: Value types should always be required if not explicitly set to optional

Closed this issue · 4 comments

Describe the bug

Currently, value types are not required even when non-optional.

This applies to #nullable enabled and #nullable disabled context.

Expected behavior

Value types should always be required if no ? is added.

Actual behavior

Value types are never required with out required keyword.

Steps to reproduce

#nullable disabled
public class TestClass
{
	public int? TestNullDisQu { get; set; }
	public int TestNullDis { get; set; } // should be required, but is not
	public required int TestNullDisReq { get; set; }
#nullable enable
	public int TestNullEn { get; set; }  // should be required, but is not
	public required int TestNullEnReq { get; set; }
	public int? TestNullEnQues { get; set; }
}

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

6.7.3

.NET Version

8.0.107

Anything else?

No response

Isn't this a dupe of #2969?.
If it's please close it

I think it is, so this can be closed. Must have missed that, when I was creating this ticket, sorry about that. But I feel like, this is more of a bug than a feature request, should we add a "bug" tag to the other ticket?

You could argue either way, because it's a feature of C# that didn't exist when the project was started, so in that aspect it's a feature request. You could argue it's a bug because you would expect a C# language feature to work intuitively and it doesn't, but changing the designation of the issue isn't going to change anything about how it's being tracked.

@phuhl SB had the NonNullableReferenceTypesAsRequired since version 6.7.0, the other way you have is to mark the properties as required