FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 707 forks source link

ParamFetcher validate stricts without explicit call #2361

Closed esorinas closed 2 years ago

esorinas commented 2 years ago

I am using version 3.3 and following the documentation, I try to define a @QueryParam that is strict as follows:

@QueryParam(name="bookId", requirements="^\d+$", nullable=false, strict=true, description="The ID of the book")

and expect to get an error if I do not send a valid bookId.

After reading this issue I understand that I will only get the error if I explicitly use the param with ParamFetcherInterface (for example, with $paramFetcher->get('bookId')).

This works fine. However, in my case (and in many others I assume), I do not use the parameter in the controller itself, but in another service, and it feels very unnatural to request the parameter with something like $bookId = $paramFetcher->get('bookId') and leave this variable unused.

For these reasons I think it would be useful to have a configuration value to allow validation without explicitly requesting the parameters. Please let me know if I am misunderstanding the usage and/or if my request makes sense to you as well.

Thanks in advance

esorinas commented 2 years ago

Apparently I was looking for something that already exists, namely

fos_rest:
    param_fetcher_listener: force

therefore I proceed to close the issue.