【问题标题】:How to add RequestBody example in NelmioApiDoc Bundle?如何在 NelmioApiDoc Bundle 中添加 RequestBody 示例?
【发布时间】:2021-10-02 07:41:12
【问题描述】:

我的注释是:

     * @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"
     *              }
     *         )
     *     )
     * )

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

【问题讨论】:

  • 在您的屏幕截图中,我只看到“id”。也许这就是问题所在?
  • @StephanVierkant,可能是什么问题? 'id' - 是来自路径的参数。我将其描述为@OA\Parameter(name="id", required=true, in="path", description="Event Id", @OA\Schema(type="integer", example=1)),顺便说一下,在这种情况下,“示例”键正在工作。

标签: rest symfony nelmioapidocbundle


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-12
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多