Hi! I have an endpoint that should return data like this:
{
"projects": [
{
"id": 1,
"name": "Test
}
]
}
But I'm unable to set the "projects" key on the JSON, it looks like this:
{
"": [
{
"id": 1,
"name": "Test"
}
]
}
How do I set the "projects" name key? My annotation looks like this:
/**
* @OA\Get(
* path="/projects",
* description="Use this method to retrieve one or many projects.",
* @OA\Response(
* response=200,
* description="",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="object",
* @OA\Property(title="projects",@OA\Items(ref="#/components/schemas/Project"))
* )
* )
* )
* )
*/
Is there a way to do it directly inside the Response block instead of having to create a schema class that has a projects property?
You're almost there, change:
@OA\Property(
title="projects",
@OA\Items(ref="#/components/schemas/Project")
)
into:
@OA\Property(
property="projects",
type="array",
@OA\Items(ref="#/components/schemas/Project")
)
Thanks!
Most helpful comment
You're almost there, change:
into: