Swagger-php: Response example cannot include arrays

Created on 17 Aug 2017  路  4Comments  路  Source: zircote/swagger-php

I am currently adding example responses to my annotations and I came across a small problem:

Whenever my response includes an array of certain objects the swagger file doesn't get generated anymore.

My examples line looks like this:
examples={"application/json": {"message":"foobar","data":[{"id":1,"name":"Item 1"},{"id":2,"name":"Item 2"}]}},

The error I get:
"[Syntax Error] Expected PlainValue, got '[' in ....

Is it not possible to include arrays of objects in my example responses?

Most helpful comment

Use the doctrine array notation with { instead of [

All 4 comments

No luck with this? Seems like a major to not be able to use arrays in examples!

Use the doctrine array notation with { instead of [

Thanks @bfanger - did I miss this in the docs?

For anyone else that might need an example:

             *     @SWG\Response(
             *         response=200,
             *         description="An array of people",
             *         examples={"application/json":
             *              {"models": { { "id": 1, "name": "Tim" },{ "id": 2, "name": "Sean" } },
             *                  "current_page": 2,
             *                  "last_page": 3,
             *                  "next_page_url": "/bookings?page=3&limit=50",
             *                  "prev_page_url": "/bookings?page=1&limit=50"
             *              }
             *         },

You didn't miss it, it's not in our docs or the doctrine-project docs.
if you encounter better documentation about doctrine annotations let me know, i'll gladly link it in the Readme.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phansys picture phansys  路  5Comments

hpatoio picture hpatoio  路  3Comments

beeradmoore picture beeradmoore  路  5Comments

kamil-kielczewski picture kamil-kielczewski  路  3Comments

praditha picture praditha  路  3Comments