Skip to content

PHP client model: Nested objects not converted to JSON #1914

@moee

Description

@moee

I have a swagger file with nested objects. If I convert the object to a string, the nested objects are not serialized to json.

To illustrate the problem I created the following minimal working example of a Swagger definition file: https://gist.github.com/moee/c5fd1d0e10e4bbec654a

Reproduction

  1. Import the provided example into the Swagger editor: http://editor.swagger.io/#/?import=https:%2F%2Fgist.githubusercontent.com%2Fmoee%2Fc5fd1d0e10e4bbec654a%2Fraw%2F0585c6482e5d4cb3bc14c26361d74ee7f553b7f8%2Fpetstore.yaml
  2. Click Generate Client > PHP

With the generated client consider the following code:

    <?php
    $petStore = new \Swagger\Client\Model\PetStore();
    $dog = new \Swagger\Client\Model\Pet();
    $dog->setName("dog");
    $petStore->setPets([$dog]);
    echo strval($petStore);

Expected result

{ "pets": [ { "name": "dog" } ] }

Actual result

{ "pets": [ {} ] }

Is this behavior intended or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions