OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Ruby] Initalize validation should apply to 'build_from_hash' too
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The changes to introduce better validation to the attributes hash in the initialize method, should also apply in the build_from_hash method.
openapi-generator version
$ docker run --rm openapitools/openapi-generator-cli version
4.2.3-SNAPSHOT
Steps to reproduce
- Generate any ruby API
- Build a hash with an incorrectly spelled attribute and create a model object with it.
E.g.
irb(main):012:0> Kubernetes::IoK8sApiBatchV1Job.new(api_version: 'batch/v1', kid: 'Job')
...
ArgumentError (`kid` is not a valid attribute in `Kubernetes::IoK8sApiBatchV1Job`. Please check the name to make sure it's valid. List of attributes: [:api_version, :kind, :metadata, :spec, :status])
vs
irb(main):013:0> Kubernetes::IoK8sApiBatchV1Job.build_from_hash(api_version: 'batch/v1', kid: 'Job')
=> #<Kubernetes::IoK8sApiBatchV1Job:0x000055ae59e2d238>
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/2226
Suggest a fix
Factor out the validation code from initialize and either call it directly from the 'build_from_hash' method, and/or add a 'strictValidation' parameter to allow backward compatibility.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the generated Ruby model's initialize and build_from_hash entry points, then compare how each handles an incorrectly spelled attribute such as kid. Done means build_from_hash rejects invalid attributes with the same validation behavior as initialize, while considering the suggested strictValidation option for backward compatibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100