NelmioApiDocBundle
NelmioApiDocBundle copied to clipboard
Nested objects properties are not displayed
Greetings,
I would like to represent in my APi doc the following response:
"52": {
"id": 52,
"address": "1 rue de la paix",
"address2": porte B,
"postcode": "75001",
"city": "Paris",
"type": {
"id": 1,
"name": "apartment"
}
}
and for this I'm trying the following code:
* @OA\Response(
* response=200,
* description="Returns stuff",
* @OA\JsonContent(
* type="array",
* @OA\Items(
* type="object",
* @OA\Property(type="int", property="id", example="52"),
* @OA\Property(type="string", property="address", example="1 rue de la paix"),
* @OA\Property(type="string", property="address2", example="porte B"),
* @OA\Property(type="string", property="postcode", example="75001"),
* @OA\Property(type="string", property="city", example="Paris"),
* @OA\Property(type="object", property="type",
* @OA\Schema(
* @OA\Property(type="int", property="id", example="24"),
* @OA\Property(type="string", property="name", example="Apartment")
* )
* ))
* )
* )
but when I refresh my API doc and check the endpoint, I only get this:
[
{
"id": 52,
"address": "1 rue de la paix",
"address2": "porte B",
"postcode": "75001",
"city": "Paris",
"type": {}
}
]
I would expect to see "id" and "name" keys in my "type" object. But as you can see, it's totally empty. Any idea why?
Thanks
There is no need to wrap the nested properties in another Schema. Try just:
* @OA\Property(type="object", property="type",
* @OA\Property(type="int", property="id", example="24"),
* @OA\Property(type="string", property="name", example="Apartment")
* )
it works indeed, thank you!