Swagger-php: How do I define property name?

Created on 20 Sep 2019  路  2Comments  路  Source: zircote/swagger-php

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?

Most helpful comment

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")
)

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings