如何在 NelmioApiDoc Bundle 中添加 RequestBody 示例?

问题描述 投票:0回答:2

我的注释是:

     * @OA\RequestBody(
     *     required=true,
     *     @OA\JsonContent(
     *         @OA\Schema (
     *              type="object",
     *              @OA\Property(property="status", required=true, description="EventStatus", type="string"),
     *              @OA\Property(property="comment", required=false, description="Change Status Comment", type="string"),
     *              example={
     *                  "status": "test status",
     *                  "comment": "test comment"
     *              }
     *         )
     *     )
     * )

我尝试添加“示例”键,但没有成功。

https://i.stack.imgur.com/of5pj.png

rest symfony nelmioapidocbundle
2个回答
6
投票

example
键必须是
@OA\JsonContent
的一部分,如下所示。

 * @OA\RequestBody(
 *     required=true,
 *     @OA\JsonContent(
 *         example={
 *             "status": "status",
 *             "comment": "comment"
 *         },
 *         @OA\Schema (
 *              type="object",
 *              @OA\Property(property="status", required=true, description="Event Status", type="string"),
 *              @OA\Property(property="comment", required=false, description="Change Status Comment", type="string"),
 *         )
 *     )
 * )

0
投票

对于属性,您必须使用以下内容:

use OpenApi\Attributes as OA;

class ObjectController
{
    #[OA\RequestBody(
        required: true,
        content: new OA\JsonContent(
            type: Object::class,
            example: [
                "status" => "status",
                "comment" => "comment"
            ]
        )
    )]
}
© www.soinside.com 2019 - 2024. All rights reserved.