Open thorhj opened 1 year ago
For positional records, validation attributes are supposed to be applied to the constructor parameters like this:
public record TestRequest([Required] string Foo);
NSwag does not support this syntax. The generated OpenAPI definition for the above request object is not including "foo" as a required property:
"foo"
"TestRequest": { "type": "object", "additionalProperties": false, "properties": { "foo": { "type": "string" } } }
Note that changing the validation attribute to apply to the property will generate the desired definition:
public record TestRequest([property:Required] string Foo);
"TestRequest": { "type": "object", "additionalProperties": false, "required": [ "foo" ], "properties": { "foo": { "type": "string", "minLength": 1 } } }
But this syntax is not supported in ASP.NET; see this issue.
This seems to still be an issue in 13.20.0 To that [property:Required] stopped working, not sure if its .net change or nswag change.
[property:Required]
However [property:BindRequired] works if you are okay with the side effects.
[property:BindRequired]
For positional records, validation attributes are supposed to be applied to the constructor parameters like this:
NSwag does not support this syntax. The generated OpenAPI definition for the above request object is not including
"foo"
as a required property:Note that changing the validation attribute to apply to the property will generate the desired definition:
But this syntax is not supported in ASP.NET; see this issue.