Skip to content

requests/responses linked examples not working #334

@fadighattas100

Description

@fadighattas100
  • L5-Swagger Version: 8.0.2 (^8.0 | grep l5-swagger)
  • PHP Version (7.3):
  • OS: docker, ubuntu

Description:

trying to use @OA\Examples but it's not rendering in the ui correctly

first i defined the @OA\Examples

` /**

 *
 *      @OA\Examples(
 *        summary="VehicleStore",
 *        example = "VehicleStore",
 *      value = {
 *  		    "result": null,
 *  			"message": "Unauthorized, you don't have access to this content, Invalid token.",
 *  			"status": 401
 *         },
 *      )
 */`

then i added request that use this example:

`/**

 * @OA\Post(
 *     operationId="vehicleStore",
 *     tags={"vehicle"},
 *     summary="Store Vehicle - with components and trips (damages & loads)",
 *     description="Store vehicle",
 *     path="/vehicle",
 *     security={{"bearerAuth":{}}},
 *
 *     @OA\RequestBody(
 *       @OA\JsonContent(
 *               allOf={
 *                      @OA\Schema(ref="#/components/schemas/APIResponse"),
 *                      @OA\Schema(ref="#/components/schemas/CustomRequestBody")
 *              },
*       examples = {
 *          @OA\Schema( ref="#/components/examples/VehicleStore")
	*
 *     }
 *
 *          )
 *      ),
 *
 *     @OA\Response(
 *         response="200",
 *         description="Successful",
 *          @OA\JsonContent()
 *      ),
 * )
 *
 * @return JsonResponse
 *
 */`

in the api-docs.json:

`

   "examples": {
        "VehicleStore": {
            "summary": "VehicleStore",
             "value": {
                "result": null,
                "message": "Unauthorized, you don't have access to this content, Invalid token.",
                "status": 401
            }
        }
    },

`

in the ui the Example Value is empty but the VehicleStore selected in the dropdown of examples:

image

Steps To Reproduce:

pls add an example to know how to use requests/responses linked examples correctly

i think this also has something related to this problem

2651

Update :

i tried to check Swagger UI online and it seems the generated json form L5 Swager is not right for swagger ui maybe i did something wrong with example definition using L5 syntax so the generated json was wrong but the current generated json from my L5 Syntax is

`

   "examples": {
        "VehicleStore": {
            "summary": "VehicleStore",
             "value": {
                "result": null,
                "message": "Unauthorized, you don't have access to this content, Invalid token.",
                "status": 401
            }
        }
    },

`

but it should be like

`

     "examples": {
          "VehicleStore_1": {
              "summary": "VehicleStore",
              "value": {
                      "result": null,
                        "message": "Unauthorized, you don't have access to this content, Invalid token.",
                          "status": 401
                           }
                  }
    }

`

to make it work with swagger ui

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions