swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.92k stars 6.03k forks source link

[Python] Root defined list response not deserialized correctly. #8873

Open eak24 opened 5 years ago

eak24 commented 5 years ago
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
kristang commented 5 years ago

Have you checked if the attribute_map in your response-class in the models folder is correct? I had an issue where the case expected from the API was not the actual case being returned - i.e. the expected case was Camel but the returned was Snake.