4

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.

Bandydan
  • 623
  • 1
  • 8
  • 24

1 Answers1

5

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")
 *             )
 *         ),
...
Bob Fanger
  • 28,949
  • 7
  • 62
  • 78
  • Thanks for the answer. Succeeded w/o Items though, it needed just to change type from array to object. – Bandydan Mar 21 '16 at 09:48