[Ruby] Update Model Creation and Attribute Validation#16114
[Ruby] Update Model Creation and Attribute Validation#16114wing328 merged 6 commits intoOpenAPITools:masterfrom Bandwidth-Sandbox:ruby_models
Conversation
modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache
Show resolved
Hide resolved
| # Check to see if the all the properties in the model are valid | ||
| # @return true if the model is valid | ||
| def valid? | ||
| warn '[DEPRECATED] the `valid?` method is obsolete' |
There was a problem hiding this comment.
the oneOf, anyOf implementation is still using this method so we need to update the implementation accordingly to replace valid? with something else.
There was a problem hiding this comment.
I believe the reference to valid? on line 126 can be removed. Since the model is created from the build_from_hash method, which now fully supports attribute validation, any model created from that method should be guaranteed to be valid. Let me know if this line can be updated to return model if model.
Edit: The valid? method contains enum attribute validation, which the custom attribute writers currently do not. Adding enum attribute validation to these writers will make the the new, build_from_hash, and assignment operators fully support attribute validation, making the valid? method obsolete in this case. Let me know if this is the solution we'd like to move forward with, in which case, I'll add enum validation to the attribute writers.
If this is not the solution we'd like to move forward with, it may make sense to leave the valid? method as is (un-deprecated) and continue to use it in the oneOf/anyOf models
There was a problem hiding this comment.
in which case, I'll add enum validation to the attribute writers.
Yes, I think we need enum validation as well in attribute writers.
I've filed #16137 to add some tests for oneOf. Will merge your change into my PR to see if there's any change in oneOf model behaviour.
There was a problem hiding this comment.
I tried removing the valid? check in oneOf template and the tests also passed so I think we are in good shape to mark valid? as deprecated
There was a problem hiding this comment.
FYI. #16137 has been merged.
We can remove valid? later in oneOf template
There was a problem hiding this comment.
Yes, I think we need enum validation as well in attribute writers.
Please submit another PR for this as I'll merge this for the time being since I've some other enhancements for Ruby models as well.
Thanks again for the PR.
There was a problem hiding this comment.
UPDATE: filed #16147 to remove invalid? in oneOf template and add anyOf support.
Addresses #15895 This PR aims to improve the model initialization and attribute validation functionalities in the Ruby generator. This PR modifies the
initializeandbuild_from_hashmethods, which currently have slightly different behaviors, to behave the same when creating model instances. It also fixes a bug in the attribute validation process, no longer allowing for invalid models to be created. This removes the need for thelist_invalid_propertiesandvalid?methods, which have been marked as deprecated.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(6.3.0) (minor release - breaking changes with fallbacks),7.0.x(breaking changes without fallbacks)@cliffano (2017/07) @zlx (2017/09) @autopp (2019/02)