-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Milestone
Description
This issue is a feature request for a support of the [Length]
attribute. Judging by the example in the Contribution guide, this issue falls into the Feature Requests category.
The System.ComponentModel.DataAnnotations
namespace has 3 (actually even more, but it is not within the scope of this Issue) Attributes responsible for the string length validation:
[MinLength(length)]
- MS Docs[MaxLength(length)]
- MS Docs[Length(minimumLength, maximumLength)]
- MS Docs
And while the first two are supported, the latter isn't.
Suppose, we have the following DTO definition:
class Dto
{
[MinLength(2), MaxLength(10)]
public string Prop1 { get; set; }
[Length(2, 10)]
public string Prop2 { get; set; }
}
Having such model SwaggerGen produces the following OpenApi
specification:
"Dto": {
"type": "object",
"properties": {
"prop1": {
"maxLength": 10,
"minLength": 2,
"type": "string",
"nullable": true
},
"prop2": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
Where the prop1
field has both maxLength
and minLength
values specified, but the prop2
field doesn't have them at all.
soroshsabz, rcollette and Frulfump
Metadata
Metadata
Assignees
Labels
No labels