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

Error validating query arguments of type array #181

Open
mam08ixo opened this issue Dec 7, 2022 · 1 comment
Open

Error validating query arguments of type array #181

mam08ixo opened this issue Dec 7, 2022 · 1 comment

Comments

@mam08ixo
Copy link

mam08ixo commented Dec 7, 2022

There are several ways to express arrays in query strings:

The array

"list": [
    "foo",
    "bar"
]

may be serialized into list[]=foo&list[]=bar or list=foo&list=bar.

Depending on the server backend, the latter variant may be required. When using this format though, request validation breaks:

foreach ($value as &$val) {
$val = $this->castToSchemaType($val, $schema->items->type ?? null);
}

Invalid argument supplied for foreach()

The issue is caused by the usage of the parse_str function, which can only handle PHP-style query args and turns multiple arguments with the same name into a string with the last value ("bar"):

parse_str($message->getUri()->getQuery(), $parsedQueryArguments);

This drawback is also mentioned in the user contributed notes of the parse_str documentation.

The objective would be to properly parse all array query string formats that are mentioned in the OpenAPI Guide.

@mam08ixo
Copy link
Author

mam08ixo commented Dec 9, 2022

\GuzzleHttp\Psr7\Query::parse handles my use case pretty well, but, as noted there, not the PHP style array.

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

No branches or pull requests

1 participant