Open phoenixy1 opened 1 week ago
Before applying any string-based validation rules, check if the value is nil and if so, automatically pass the validation if the field has nullable:true.
may I know if you've time to contribute a fix?
ruby model templates can be found in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache
Description
Ruby generator applies
minLength
validation to nullable string fields that arenull
. Per everything I can find, string validation is not supposed to be applied tonull
values if the field is nullable, becausenullable
indicates that the value can be null OR a string. However, the generator is running.to_s
on whatever is passed in, even if it isnil
, and then validatingminLength
based on that, which is causing all fields with a specifiedminLength
to fail validation ifnil
is passed instead of a string. I haven't checked whether this applies to other forms of string properties, likepattern
andformat
, but it seems like there is a risk that it does.You can see an example here where
document_number
is marked as nullable: https://github.com/plaid/plaid-ruby/blob/master/lib/plaid/models/watchlist_screening_search_terms.rb#L67But is still being subjected to a length check even if it's null: https://github.com/plaid/plaid-ruby/blob/master/lib/plaid/models/watchlist_screening_search_terms.rb#L132
openapi-generator version
Using 6.3.0. I did not test on newer libraries, but I did not see a bug fix or existing bug for this submitted anywhere.
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/9141 https://github.com/OpenAPITools/openapi-generator/issues/16629
Suggest a fix
Before applying any string-based validation rules, check if the value is
nil
and if so, automatically pass the validation if the field hasnullable:true
.