Swagger-php: Using examples in Response

Created on 26 Aug 2015  路  1Comment  路  Source: zircote/swagger-php

Hi there,

The swagger 2.0 specification supports providing examples as part of a response definition:

https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#exampleObject

and I also noticed that there is a $examples public variable in Annotations/Response.php but I could not seem to find how to use it. I was wondering if anyone has a working example of using 'examples' as part of a Response definition.

Bests,

Yoanis.

Most helpful comment

There is no @SWG\Examples because _examples_ doesn't have a defined structure, therefor it wouldn't add any benefit compared to using doctrine-annotations's object-notation.

To create the the example in shown in the spec with swagger-php, you'll write:

/**
 * @SWG\Response(
 *   response=200,
 *   description="...",
 *   examples={
 *     "application/json": {
 *       "name"="Puma",
 *       "type"="Dog",
 *       "color"="Black",
 *       "gender"="Female",
 *       "breed"="Mixed"
 *     }
 *   }
 * )
 */

>All comments

There is no @SWG\Examples because _examples_ doesn't have a defined structure, therefor it wouldn't add any benefit compared to using doctrine-annotations's object-notation.

To create the the example in shown in the spec with swagger-php, you'll write:

/**
 * @SWG\Response(
 *   response=200,
 *   description="...",
 *   examples={
 *     "application/json": {
 *       "name"="Puma",
 *       "type"="Dog",
 *       "color"="Black",
 *       "gender"="Female",
 *       "breed"="Mixed"
 *     }
 *   }
 * )
 */
Was this page helpful?
0 / 5 - 0 ratings