-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[BUG] PHP Client - ObjectSerializer::buildQuery flattens array params resulting invalid URL params (param=a¶m=b vs param[]=a¶m[]=b) #19233
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
Comments
… resulting invalid URL params (param=a¶m=b vs param[]=a¶m[]=b) OpenAPITools#19233
This is the default behaviour: // 0=blue&1=black&2=brown
ObjectSerializer::buildQuery(['blue', 'black', 'brown']); see test provider openapi-generator/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php Lines 304 to 306 in fb023b1
I believe this is wrong behaviour It appears that the following results in CORRECT query parameters // color%5B%5D=blue&color%5B%5D=black&color%5B%5D=brown
ObjectSerializer::buildQuery(['color[]' => ['blue', 'black', 'brown']]); but there is no way you can format the YAML OpenAPI data and then pass it to I think this is related to #11225 |
According to OAI/OpenAPI-Specification#1006 (comment)
In our case, this is a PHP client and the brackets Example / POC:
index.php add the following: <?php
print_r($_GET); Then run the local webserver: WRONG
GOOD
|
… resulting invalid URL params (param=a¶m=b vs param[]=a¶m[]=b) #19233 (#19236) * [BUG] PHP Client - ObjectSerializer::buildQuery flattens array params resulting invalid URL params (param=a¶m=b vs param[]=a¶m[]=b) #19233 * Added tests (replaced old provider data). This looks like a breaking change * Fix space --------- Co-authored-by: Serban Ghita <[email protected]>
This bug was fixed in the v7.8.0 release, should be closed? |
@jtreminio thanks for the reminder |
Description
ObjectSerializer::buildQuery
flattens array params (e.g.exclude[]
) and instead ofexclude[]=a&exclude[]=b
it outputsexclude=a&exclude=b
resulting in HTTP contract errors:OpenAPI declaration file content or url
This is the OpenAPI relevant schema:
Results in generated PHP code from DefaultApi.php:
This appears to confuse `\GuzzleHttp\Psr7\Query::build($data, $encoding_type); in 7.3.0 and it's the same in 7.7.0
such that the output is
causing the HTTP contract to fail.
openapi-generator version
Suggest a fix
If you change
exclude
field declaration fromarray
toobject
then the outputthen the output is a single layer array
Unfortunately this cannot be added to the OpenAPI schema because it doesn't make sense, the param is actually an
array
not anobject
.Then I think the solution is to change a line of code inside
ObjectSerializer::toQueryValue
7.3.0this should also take into account
$openApiType === 'array'
The text was updated successfully, but these errors were encountered: