Skip to content

php-nextgen - Fix flatten() to support arrays of files #21458

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lukascernydis
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants