swagger-api / swagger-api/swagger-codegen

[RUBY] Json object defined with `additionalProperties` in swagger.yml gets validated against `array` datatype instead of `hash`

Open
#7,310 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Ruby Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I have a JSON input object with one of its keys as another object but variable key-value pairs:

parentObject:
    type: object
    properties:
      key1:
        type: object
        additionalProperties:
          description: Name of custom property
          type: string
          example: 'Ellie'

In generated ruby wrapper, this key1 object is getting validated against array datatype instead of hash which is causing the request failure.
For example, following piece of code is not working:

input_params = MyApi::ObjectCreationApi.new({'key1'=> {'name'=>'abc', 'place'=>'bcd'}})
MyApi::ObjectsApi.new.create_object(input_params)
Swagger-codegen version

2.2.3

Suggest a fix/enhancement

Type of key1 should be matched against hash not array.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Ruby client generated from the swagger.yml schema, focusing on validation for an object using additionalProperties. Reproduce the shown create_object call and trace why key1 is treated as an array; done when the generated wrapper accepts its hash value and the request succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.