dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.32k stars 1.25k forks source link

Unable to use json arrays in API Blueprint response #559

Closed TUNER88 closed 9 years ago

TUNER88 commented 9 years ago

Example

/**
 * Show all categories
 *
 * Get a JSON representation of all the categories.
 *
 * @Get("/{?page,pageSize}")
 * @Versions({"v1"})
 * @Parameters({
 *      @Parameter("page", description="The page of results to view.", default=1),
 *      @Parameter("pageSize", description="The amount of results per page.", default=20)
 * })
 * @Response(200, body={"data": "foo", "bar": []})
 */
public function index(Request $request)
{
}

Generates following error message:

[Doctrine\Common\Annotations\AnnotationException]                                                                            
[Syntax Error] Expected PlainValue, got '\' at position 407 in method App\Http\Controllers\Api\CategoryController::index().  

How can I escape [ and ]?

lightvision commented 9 years ago

It's a parser limitation. The answer was already here on closed issues, but instead of [] you must use {}.

TUNER88 commented 9 years ago

@lightvision array and object are different datatypes, it so dread API tests would fail. Documentation and real API should return same responses, otherwise the documentation is incorrect.

lightvision commented 9 years ago

You must {} in documentation. When rendered it will have the correct [] for responses. And to be complete: its an annotaion parser limitation. Check your generated md documentation file and you will see the correct formated response.

jasonlewis commented 9 years ago

As @lightvision has said it's a limitation of the parser. But the resulting documentation that's generated will be correct. You just need to use curly braces in your docblocks, even for arrays.

jasonlewis commented 9 years ago

Perhaps one day I'll see if I can find away around the limitation, but it's not a big issue right now.

TUNER88 commented 9 years ago

Thx, I've got it. Some notes about this limitation in docs would be really nice.