restsymfonynelmioapidocbundle

How to add RequestBody example in NelmioApiDoc Bundle?


My annotations is:

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

I tried to add an "example" key, but it didn't work.

https://i.sstatic.net/of5pj.png


Solution

  • example key must be part of the @OA\JsonContent as below.

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