4
votes

I am concerned on generating Model/Example value section for my GET request with Swagger. The link to official example shows that section perfectly.

In official docs it is generated using existing model:

     *     @SWG\Schema(ref="#/definitions/User")

I don't have such an option, because my properties is generated by REST.

I have tried the following way:

/**
 * @SWG\Get(
...
 *     @SWG\Response(
 *         response="200",
 *         description="Ok",
 *         @SWG\Schema(
 *             type="array",
 *             @SWG\Property(property="firstname", type="string", example="Steven")
 *         ),
 *     ),
 * )
 */

It is not working and answers:

fetching resource list: http://localhost/dist/swagger.json; Please wait.

Any help is highly appreciated. Thanks in advance.

1

1 Answers

5
votes

The GET /pet/findByStatus is generated in one of the examples:
github.com/zircote/swagger-php/.../Examples/petstore.swagger.io/controllers/PetController.php

The reason your snippet isn't working is because you're adding a property to an array type, which isn't supported.

To describe the contents of the array you'll need the @SWG\Items annotation:

...
 *         @SWG\Schema(
 *             type="array",
 *             @SWG\Items(
 *                 type="object",
 *                 @SWG\Property(property="firstname", type="string", example="Steven")
 *             )
 *         ),
...