1

I'm using NelmioApiDocBundle and Swagger to describe my API.

I want to describe my response object that contains another object:

For example - json str:

"Person": {
    "firstname": "John",
    "lastName": "Smith",
    "car": {
       "brand": "Tesla",
       "price": "1000"
    }
}

My PHP look like:

use Swagger\Annotations as SWG;

class Person {

    /**
     * @SWG\Property(
     *     title="firstName",
     *     type="string",
     *     required={"true"},
     *     description="Last Name"
     * )
     */
    protected $firstName;
    /**
     * @SWG\Property(
     *     title="lastName",
     *     type="string",
     *     required={"true"},
     *     description="First Name"
     * )
     */
    protected $lastName;        
    /**
     * @SWG\Property(
     *     title="data",
     *     required={"true"},
     *     description="The fetched article",
     *     type="object", <- THAT IS THE PROBLEM
     *     @SWG\Property(property="Car", type=Car::class)
     * )
     */
    protected $car;
}

class Car {

    /**
     * @SWG\Property(
     *     title="brand",
     *     type="string",
     *     required={"true"},
     *     description="brand"
     * )
     */
    protected $brand;
    /**
     * @SWG\Property(
     *     title="price",
     *     type="string",
     *     required={"true"},
     *     description="price"
     * )
     */
     protected $price;

}

Configuration:

  • php: "7.1.7"
  • nelmio/api-doc-bundle: "3.0"
  • symfony/symfony: "3.4.0",
  • zircote/swagger-php": "2.0"
Saveen
  • 4,120
  • 14
  • 38
  • 41
Joozty
  • 460
  • 2
  • 12
  • 40

1 Answers1

0

Finally I found a solution:

This will be solved in this Pull Request on Github

Joozty
  • 460
  • 2
  • 12
  • 40
  • 1
    Please include a solution in the answer itself. Links are great and all, but an answer should, well, answer a question. See https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers – Ilja Everilä Apr 04 '18 at 20:06