Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Array to string conversion when using array in @QueryParam requirements option #564

Closed
kwn opened this issue Jan 14, 2015 · 5 comments · Fixed by #796
Closed

Notice: Array to string conversion when using array in @QueryParam requirements option #564

kwn opened this issue Jan 14, 2015 · 5 comments · Fixed by #796

Comments

@kwn
Copy link

kwn commented Jan 14, 2015

Hi guys,

I found a bug. While I'm trying to visit documentation pages I get an exception:

Notice: Array to string conversion in /var/www/vhosts/localhost.crkl/httpdocs/vendor/nelmio/api-doc-bundle/Nelmio/ApiDocBundle/Extractor/Handler/FosRestHandler.php line 86

500 Internal Server Error - ContextErrorException 

My annotations:

/**
 * @Rest\RouteResource("Venue")
 */
class VenueController extends FOSRestController
{
    /**
     * @param ParamFetcher $paramFetcher
     * @return array
     *
     * @Rest\View()
     * @Rest\QueryParam(name="lat", strict=true)
     * @Rest\QueryParam(name="lng", strict=true)
     * @Rest\QueryParam(name="range", strict=true, requirements={
     *     @Assert\GreaterThan("0"),
     *     @Assert\Regex("/\d+/")
     * }, default="10")
     * @Rest\QueryParam(name="product", strict=true, requirements={
     *     @Assert\Regex("/\d+/")
     * }, nullable=true)
     * @ApiDoc()
     */
    public function cgetAction(ParamFetcher $paramFetcher)
    {
        // [...]
    }

So, the reason of this error is an array in requirements option. After removing range QueryParam and change product QueryParam to:

@Rest\QueryParam(name="product", strict=true, requirements=@Assert\Regex("/\d+/"), nullable=true)

everyting works fine.

@solazs
Copy link

solazs commented Jan 30, 2015

Same here with

/**
     * @Annotations\QueryParam(name="offset", requirements="\d+", nullable=true, description="Offset from which to start listing news.")
     * @Annotations\QueryParam(name="limit", requirements="\d+", default=null, description="How many news to return.")
     * @Annotations\QueryParam(name="tags", array=true, default={}, description="Tags to filter the query")
     * @Annotations\QueryParam(name="services", array=true, default={}, description="Service IDs to filter the query")
     * @Annotations\QueryParam(name="organizations", array=true, default={}, description="Organization IDs to filter the query")
     * @ApiDoc(
     *   section = "News",
     *   resource = true,
     *   description = "get news for the current user",
     *   statusCodes = {
     *     200 = "Returned when successful",
     *     401 = "Returned when token is expired or invalid",
     *     403 = "Returned when not permitted to query",
     *     404 = "Returned when resource is not found"
     *   },
     *   requirements ={
     *      {"name"="_format", "requirement"="xml|json", "description"="response format"}
     *   }
     * )
     */

@willdurand
Copy link
Collaborator

@advancingu could you open a PR with your fix please?

@advancingu
Copy link

I did but you closed it due to lack of tests (understandable). I simply don't have the time for it.
#596

@willdurand
Copy link
Collaborator

Should be fixed in 2.11.2.

@zhukovra
Copy link
Contributor

zhukovra commented Feb 1, 2016

@willdurand, no, it shouldn't. You can see it in my PR #796, where new test is added, with plain array in QueryParam requirements:

@QueryParam(name="param1", requirements={@Assert\NotNull(), @Assert\NotBlank()}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants