Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5199
Closed
Open
Issue created Feb 03, 2020 by Administrator@rootContributor

[BUG] [Ruby] Initalize validation should apply to 'build_from_hash' too

Created by: NeilW

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
  1. Generate any ruby API
  2. 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.

Assignee
Assign to
Time tracking