-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
[BUG] PHP Client - ObjectSerializer::buildQuery flattens array params resulting invalid URL params (param=a¶m=b vs param[]=a¶m[]=b) #19233 #19236
Conversation
… resulting invalid URL params (param=a¶m=b vs param[]=a¶m[]=b) OpenAPITools#19233
Looks like I need to run |
pushed the template fix 59a8412 |
@wing328 can you please restart https://github.com/OpenAPITools/openapi-generator/actions/runs/10145363184 - I pushed the fix |
ping @wing328 |
'deepObject array, explode on, required true' => [ | ||
$array, 'color', 'array', 'deepObject', true, true, 'color=blue&color=black&color=brown', | ||
$array, 'color', 'array', 'deepObject', true, true, 'color%5B0%5D=blue&color%5B1%5D=black&color%5B2%5D=brown', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to https://swagger.io/docs/specification/serialization/, the behavior for an array with deepObject style and explode set to true should be undefined.
if you want to send an array in query parameter, should the style be something else instead of deepObject
?
(i'm not against this change as it allows users to send array with index but just want to confirm that's what the server intends to receive from the PHP client)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wing328 I presume you are referring to the paragraph:
deepObject – simple non-nested objects are serialized as paramName[prop1]=value1¶mName[prop2]=value2&.... The behavior for nested objects and arrays is undefined.
I believe the reson for "The behavior for nested objects and arrays is undefined." is explained in this comment:
According to OAI/OpenAPI-Specification#1006 (comment):
Tooling will have to deal with it, and I'd suggest just clobbering values. It's really up to the user to define things that make sense, within the defined behavior.
Authoring tools might be able to provide warnings to users in such a case.
My justification for this BEHAVING like that is #19233 (comment).
if you want to send an array in query parameter, should the style be something else instead of deepObject?
My justification for this BEING in deepObject
is that my problem was in the query params as opposed to body of a form payload.
Because of the PHP behaviour of $_GET and $_POST I believe both form
+ deepObject
with explode: true
should serialize with brakets []
(i'm not against this change as it allows users to send array with index but just want to confirm that's what the server intends to receive from the PHP client)
If you code in PHP, the expectations are exactly like in my POC
PS: The way we mitigated this is by migrating the OpenAPI schema from get:
to
post:
requestBody:
...
color:
type: array
items:
type: string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the explanation.
let's give it a try
Fix for #19233