Skip to content

[PHP Client] Nested models do not deserialize correctly #635

@who

Description

@who

If you have nested models in your swagger spec, the nested object does not deserialize correctly.

Given this Swagger 2.0 spec snippet:

...
  "definitions": {
    "BookAuthor": {
      "properties": {
        "name": {
          "type": "string"
        }
      }
    },
    "Book": {
      "properties": {
        "name": {
          "type": "string"
        },
        "bookAuthor": {
          "$ref": "#/definitions/BookAuthor"
        }
      }
    }
  }
...

The PHP client will yield this JSON when returning Book responses.

{"name":"My Book Name","book_author":null}

The fix for this appears to be in the deserialize() method of APIClient.Mustache

Here's the apparent fix:

Change this:

...
      foreach ($instance::$swaggerTypes as $property => $type) {
        if (isset($data->$property)) {
          $original_property_name = $instance::$attributeMap[$property];
          $instance->$property = self::deserialize($data->$original_property_name, $type);
        }
      }
...

To this:

...
      foreach ($instance::$swaggerTypes as $property => $type) {
        $original_property_name = $instance::$attributeMap[$property];
        if (isset($original_property_name)) {
          $instance->$property = self::deserialize($data->$original_property_name, $type);
        }
      }
...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions