NelmioApiDocBundle icon indicating copy to clipboard operation
NelmioApiDocBundle copied to clipboard

Symfony form in GET-request

Open nadrshin opened this issue 6 years ago • 9 comments

Is it possible to use symfony form in GET-reqeust?

nadrshin avatar Mar 12 '18 13:03 nadrshin

would that mean a GET request with a body? this is very unusual, and some proxies might discard the body. afaik elasticsearch used to do it, but they switched to POST meanwhile because GET with body was creating problems with tools not expecting it.

dbu avatar Mar 12 '18 13:03 dbu

Without body.

Let's say I have a form FilterType with two fields ("name" and "surname") and block prefix "filter". In NelmioApiDocBundle v2 I used this form in "input":

input = "ApiBundle\Form\Type\FilterType"

In the sandbox I made the following request:

/api/v1/users?filter[name]=Michael&filter[surname]=Phelps

How can I do the same in the third version?

nadrshin avatar Mar 12 '18 14:03 nadrshin

ah, that sounds useful. maybe @GuilhemN can help here?

dbu avatar Mar 12 '18 16:03 dbu

That's not supported in 3.x unfortunately, mostly due to the way parameters are implemented in swagger. That could be added but the biggest challenge is to find a nice syntax.

Maybe we need to rethink @Model to cover all cases more nicely. What do you think about extending all zircote/swagger-php annotations in the bundle and add a model field to the annotations needing it instead of having @Model ? That would allow us to provide features more integrated with zircote/swagger-php annotations...

GuilhemN avatar Mar 13 '18 19:03 GuilhemN

could it be possible to add a model field to zircote/swagger-php instead? that might be more straightforward and less confusing. but is only possible if the model field would make sense for zircote itself as well - but from how i understand things, it would make sense.

dbu avatar Mar 14 '18 07:03 dbu

Thinking about it again we could also use the ref field:

/**
 * @Response(response=200,
 *      @Schema(ref=@Model(type=""))
 * )
 */

when it is not clear what @Model should be used for. That makes things much clearer imo.

could it be possible to add a model field to zircote/swagger-php instead? that might be more straightforward and less confusing. but is only possible if the model field would make sense for zircote itself as well - but from how i understand things, it would make sense.

Well they use ref a lot, I don't think this would be accepted. Plus we would have no way to pass options as well (serialization groups for instance).

GuilhemN avatar Mar 17 '18 13:03 GuilhemN

We have the same problem. We use Symfony Forms in GET requests for filtering content. That would be nice feature!

jmalinens avatar Mar 19 '18 15:03 jmalinens

I have faced with the same issue during describing JSON:API endpoints. For pagination I'm using query page[number] and page[size] parameters names. Instead of FormType I have described page as following structure:

class PaginationParams
{
    public $number;
    public $size;
}

It would be great to have a possibility to add a reference to such models to describe query parameters. Currently, the only way how to do this is to copy-paste query parameters annotations in each controller action.

BTW OpenAPI 3.0 supports specific serialization format deepObject which provides a possibility to describe query parameter array keys with square brackets.

dbalabka avatar Sep 05 '18 14:09 dbalabka

Are there any updates on this?

mstosicfb avatar Sep 22 '22 16:09 mstosicfb