[csharp][netcore] Do not validate enum parameters#9594
[csharp][netcore] Do not validate enum parameters#9594wing328 merged 1 commit intoOpenAPITools:masterfrom
Conversation
| {{^isEnum}} | ||
| {{#maxLength}} | ||
| // {{{name}}} ({{{dataType}}}) maxLength | ||
| if(this.{{{name}}} != null && this.{{{name}}}.Length > {{maxLength}}) |
There was a problem hiding this comment.
Instead of not validating for enum params. What about if:
this.{{{name}}}.ToString().Length > {{maxLength}} so that it will work for other case like:
uuid_property:
description: This is description
type: string
format: uuid
maxLength: 36
Else, it will also break at: UuidProperty.Length > 36
There was a problem hiding this comment.
I'm not sure I understand what you mean, are you saying strings with format: uuid are not String objects and thus need the toString() call? Looks like a separate issue if that's what you meant.
Here the fix simply skips adding validation checks if the property specifies an enum, which is a very reliable and future-proof way, me thinks.
There was a problem hiding this comment.
Strings with format: uuid are of Guid type in c#. The comment is valid however and worth some thought. If there is a simple way to keep validation and still have the enum behavior that might be worth exploring. However having validation for enum parameters would mean that they might break at some point in the future when one decides to use the forbidden values for the first time instead of breaking immediately.
There was a problem hiding this comment.
Yes. I meant to say is Strings with format: uuid are of Guid type in c#.
And, as the above validations like MaxLength/ MinLength are specific to string type. Its better to convert to string type using ToString() before validating the property.
Similar to that I found in ruby-client -> https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache#L302 ( to_s converts to string IIUC)
Besides, it might be separate issue but the gist of the bug is same.
There was a problem hiding this comment.
Guids really don't have the same issue however. Reason being that it performs its own validation. Of course the same applies you could technically have the validation parameters in the spec I guess. It just makes no sense whatsoever.
This fixes #9586 . We do not wish to validate enum type parameters further as they are already constrained by their possible values so any validation is superfluous.
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master,5.1.x,6.0.x@mandrean (2017/08) @frankyjuang (2019/09) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05)