swagger-api / swagger-api/swagger-codegen

[Python] Root defined list response not deserialized correctly.

Open
#8,873 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When referencing a model within 'definitions', the serialization protocol doesn't properly parse a list of objects.

More specifically, there is a problem with a model definition that looks like this when it is linked as the root definition of the response:

my_object_array:
  type: array
  items:
    type: object
    properties:
      prop1:
        type: string
      prop2:
        type: string

What happens is the deserializer doesn't recognize the list as a list of swagger type objects. When the definition is changed to:

type: array
items:
  $ref: '#/definitions/my_object'

And definitions would look like:

my_object:
  type: object
    properties:
      prop1:
        type: string
      prop2:
        type: string

I'm not entirely sure why these two samples have different behavior - but it appears that inline response definitions are treated differently than linked definitions. When the inline version of the client recieves a response, it passes a klass of 'list[my_object]' (the correct behavior) and continues to parse the internal elements correctly within api_client.ApiClient.__deserialize(). However, if using the first definition of the object, the klass becomes 'my_object_array' and the corresponding swagger_types and attribute_map dictionaries are passed as empty and the data is returned without being deserialized, according to line 604 of apiClient.

Swagger-codegen version

2.3.1

Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

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 in api_client.ApiClient.__deserialize(), especially around line 604, and compare how the two YAML response definitions produce the klass, swagger_types, and attribute_map values. Reproduce the root array case with the provided definitions; done means the inline object list is deserialized consistently rather than returned without conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
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.