Skip to content

Conversation

@lukascernydis
Copy link
Contributor

@lukascernydis lukascernydis commented Jun 24, 2025

Previously, FormDataProcessor::flatten() unconditionally passed all values through ObjectSerializer::toString(), which caused an error when flattening arrays containing file resources (e.g. for OpenAPI multipart/form-data definitions with type: string, format: binary).

This change adds a check for is_resource() to preserve stream handles without serialization, ensuring correct behavior when uploading files.

The error is not in generator itself but rather in the generated utility PHP class FormDataProcessor.php

Reproducible by generating method that utilizes any file or file list. For example:

            requestBody:
                required: true
                content:
                    multipart/form-data:
                        schema:
                            type: object
                            required:
                                - files
                            properties:
                                files:
                                    type: array
                                    items:
                                        type: string
                                        format: binary

@renepardon

…orm-data

Previously, FormDataProcessor::flatten() unconditionally passed all values through ObjectSerializer::toString(),
which caused an error when flattening arrays containing file resources (e.g. for OpenAPI
multipart/form-data definitions with `type: array`, `items: type: string, format: binary`).

This change adds a check for is_resource() to preserve stream handles without serialization,
ensuring correct behavior when uploading multiple files in a single request.
@wing328
Copy link
Member

wing328 commented Jun 26, 2025

thanks for the pr

please follow step 3 to update the samples

@wing328
Copy link
Member

wing328 commented Jun 29, 2025

thanks again for the fix

is it correct to say that you've been using this fix and confirm it's working as expected ?

@lukascernydis
Copy link
Contributor Author

Yes, after this edit, the TypeError no longer appears in ObjectSerializer::toString($val) and file is correctly included in the request. Same for list of files.

Thank you for guiding me.

@wing328 wing328 merged commit b444de2 into OpenAPITools:master Jul 2, 2025
15 checks passed
@wing328
Copy link
Member

wing328 commented Jul 2, 2025

thanks for the PR

let's give it a try

simonhammes added a commit to simonhammes/openapi-generator that referenced this pull request Jul 25, 2025
wing328 pushed a commit that referenced this pull request Jul 28, 2025
* [php] Backport #21458 to php client

Fixes #21485

Credits to @jozefbriss

* [php] Fix deprecation warning when running integration tests

OpenAPI\Client\FakeHttpClient::setResponse(): Implicitly marking parameter $response as nullable is deprecated, the explicit nullable type must be used instead

---------

Co-authored-by: simonhammes <[email protected]>
Goopher pushed a commit to Goopher/openapi-generator that referenced this pull request Sep 9, 2025
…s#21632)

* [php] Backport OpenAPITools#21458 to php client

Fixes OpenAPITools#21485

Credits to @jozefbriss

* [php] Fix deprecation warning when running integration tests

OpenAPI\Client\FakeHttpClient::setResponse(): Implicitly marking parameter $response as nullable is deprecated, the explicit nullable type must be used instead

---------

Co-authored-by: simonhammes <[email protected]>
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