-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[PHP] Fix converting objects to formdata #20888
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
Conversation
|
https://github.com/OpenAPITools/openapi-generator/actions/runs/13861177290/job/38790025192?pr=20888 please update the samples to fix the CI failure |
cd93a34 to
8834b29
Compare
|
Pending unit tests. |
a039ea2 to
98c392a
Compare
98c392a to
abbbc2d
Compare
|
Pinging maintainers: @jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ybelenko (2018/07), @renepardon (2018/12) |
This reverts commit 2eaa937.
|
do we need to apply the same fix to |
|
I'll take a look for |
modules/openapi-generator/src/main/resources/php-nextgen/ObjectSerializer.mustache
Show resolved
Hide resolved
|
@wing328 I noticed that neither I'd suggest adding them in at some point, even if it's mostly copy/paste. |
|
linux tests passed via #20926 |
agreed. even better is to migrate to echo api tests instead: https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests#echo-server, as we're moving away from petstore api tests |
|
tested locally and the result is good |
This reverts commit 8f24df4.
Currently the PHP generator cannot handle objects for content-type
application/x-www-form-urlencodedandmultipart/form-data.This is because all parameters are run through
ObjectSerializer::toFormValue()which callsObjectSerializer::toString()when a value is not aSplFileObject. So, aPetobject will be attempted to be turned into a string but will fail. The issue is made worse when you have arrays of objects.Additionally, the API methods will assign the return value of
ObjectSerializer::toFormValue()to a single array key. Anything nested will not work.Given the following:
and running with:
We see that arrays cause issues:
Objects are converted to a JSON string, and arrays are simply string literal
"Array"in$formParams:Instead, with the new
ObjectSerializer::flatten_array()method, we flatten the array and make it compatible with formdata, where$formParamsremains a single-level array but all nested keys are set in the correct formdata format:PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)