-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Describe the issue or request
Please describe the issue or feature request.
Storage team recently have new feature have swagger change as following.
The autorest generated C# code from it with always fail in validation, when any of the optional properties is null.
Since the properties are optional, we should skip validate if it’s null.
Swagger:
"DateAfterModification": {
"properties": {
"daysAfterModificationGreaterThan": {
"type": "number",
"multipleOf": 1.0,
"minimum": 0,
"description": "Value indicating the age in days after last modification"
},
"daysAfterLastAccessTimeGreaterThan": {
"type": "number",
"multipleOf": 1.0,
"minimum": 0,
"description": "Value indicating the age in days after last blob access. This property can only be used in conjuction with last access time tracking policy"
}
},
"description": "Object to define the number of days after object last modification Or last access. Properties daysAfterModificationGreaterThan and daysAfterLastAccessTimeGreaterThan are mutually exclusive"
},Generated C# code:
The generated C# code to validate this item will be following (with autorest 2.0.4413, 3.0.6306)
Please note the validation will fail when any of DaysAfterModificationGreaterThan or DaysAfterLastAccessTimeGreaterThan is null (null %1 = null, null != 0). But since both properties are optional, null should be a valid value for the 2 properties.
public virtual void Validate()
{
if (DaysAfterModificationGreaterThan < 0)
{
throw new ValidationException(ValidationRules.InclusiveMinimum, "DaysAfterModificationGreaterThan", 0);
}
if (DaysAfterModificationGreaterThan % 1 != 0) // ensures that the value is a multiple of 1.0
{
throw new ValidationException(ValidationRules.MultipleOf, "DaysAfterModificationGreaterThan", 1);
}
if (DaysAfterLastAccessTimeGreaterThan < 0)
{
throw new ValidationException(ValidationRules.InclusiveMinimum, "DaysAfterLastAccessTimeGreaterThan", 0);
}
if (DaysAfterLastAccessTimeGreaterThan % 1 != 0)
{
throw new ValidationException(ValidationRules.MultipleOf, "DaysAfterLastAccessTimeGreaterThan", 1);
}
}Describe your ideas for solutions
Please describe how you think a change or changes might work. Consider
how these changes might work for multiple services.
Suggested change:
Autorest generated code should first check if the value is null or not, and only do validation when it’s not null, like:
if (DaysAfterModificationGreaterThan != null && DaysAfterModificationGreaterThan % 1 != 0) // ensures that the value is a multiple of 1
{
throw new ValidationException(ValidationRules.MultipleOf, "DaysAfterModificationGreaterThan", 1);
}Add labels
As appropriate, select a label to describe how hard the issue is to work
around or how hard it would be to do without a particular feature that
could help make it easier. These labels start with "workaround".
Not workaround now, until remove the validation from swagger.
Also select a label that describes how many instances of the workaround
you would have to do without the bug being fixed or feature implemented.
These labels start with "instances".
These labels will help priority bug fixes and feature requests.
If this bug or feature request is for older versions of autorest, please
remove the v3 label and add the v2 label as appropriate.