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

[BUG] PHP Client - ObjectSerializer::buildQuery flattens array params resulting invalid URL params (param=a&param=b vs param[]=a&param[]=b) #19233 #19236

Merged
merged 3 commits into from
Aug 7, 2024

Conversation

serbanghita
Copy link
Contributor

@serbanghita serbanghita commented Jul 24, 2024

Fix for #19233

@serbanghita
Copy link
Contributor Author

Looks like I need to run bin/generate-samples.sh locally and commit again

@serbanghita
Copy link
Contributor Author

pushed the template fix 59a8412

@serbanghita
Copy link
Contributor Author

@wing328 can you please restart https://github.com/OpenAPITools/openapi-generator/actions/runs/10145363184 - I pushed the fix

@serbanghita
Copy link
Contributor Author

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',
Copy link
Member

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)

Copy link
Contributor Author

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&paramName[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

Copy link
Member

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

@wing328 wing328 merged commit 539aab0 into OpenAPITools:master Aug 7, 2024
15 checks passed
@wing328 wing328 added this to the 7.8.0 milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants