NelmioApiDoc: schema gets polluted with redundant data

74 Views Asked by At

I would like to reuse a common response structure, normally it looks like this:

 * @OA\Response(
 *     response=200,
 *     description="Success",
 *     @OA\JsonContent(
 *         @OA\Property(property="status", type="string", example="OK"),
 *         @OA\Property(property="code", type="number", example="20000"),
 *         @OA\Property(
 *             property="data",
 *             ref=@Model(type=OutputDto::class)
 *         )
 *     )
 * )

Which produces the following view

enter image description here

As a solution to my problem I added a common schema:

        SuccessResponse:
            description: OK
            properties:
                status: { type: string, example: OK }
                code: { type: integer, example: 20000 }
                data: { type: array }

and changes the response to

 * @OA\Response(
 *     response=200,
 *     description="Success",
 *     @OA\JsonContent(
 *         allOf={
 *             @OA\Schema(ref="#/components/schemas/SuccessResponse"),
 *             @OA\Schema(type="object",
 *               @OA\Property(
 *                 property="data",
 *                 ref=@Model(type=OutputDto::class)
 *               )
 *             )
 *         }
 *     )
 * )

which produces an ugly, nearly unreadable output:

enter image description here

Is there a solution to this?

P.S. NelmioApiDocBundle v4.9.0

0

There are 0 best solutions below