Skip to content

[php-nextgen] Fix object query parameters given as a model, fixes #24684 - #24685

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
Frankisgek:php-next-gen-object-serializer
Aug 12, 2026
Merged

[php-nextgen] Fix object query parameters given as a model, fixes #24684#24685
wing328 merged 3 commits into
OpenAPITools:masterfrom
Frankisgek:php-next-gen-object-serializer

Conversation

@Frankisgek

@Frankisgek Frankisgek commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes the query serialization of object-typed parameters when the value is a generated model
instance.

fix #24684

PR checklist

What was wrong

ObjectSerializer::toQueryValue() prepared object-typed values with a plain (array) cast:

$value = (in_array($openApiType, ['object', 'array'], true)) ? (array)$value : $value;

Generated models keep their values in a single protected array $container, not in public
properties, so casting a model with (array) yields PHP's mangled property name
("\0*\0container") as the only key instead of the model's fields. The result was a query string
the server cannot interpret, produced silently.

Given this spec:

openapi: 3.0.3
info:
  title: deepObject query param repro
  version: 1.0.0
paths:
  /items:
    get:
      operationId: listItems
      parameters:
        - name: filter
          in: query
          style: deepObject
          explode: true
          schema:
            $ref: '#/components/schemas/Filter'
      responses:
        '200':
          description: ok
components:
  schemas:
    Filter:
      type: object
      properties:
        requirements:
          type: array
          items:
            type: integer
        status:
          type: string

and new Filter(['requirements' => [1, 2], 'status' => 'published']):

# before (url-decoded; \0 shown as <NUL>)
filter[<NUL>*<NUL>container][requirements][0]=1&filter[<NUL>*<NUL>container][requirements][1]=2&filter[<NUL>*<NUL>container][status]=published

# after
filter[requirements][0]=1&filter[requirements][1]=2&filter[status]=published
The fix

Object-typed values now go through sanitizeForSerialization(), which for anything implementing
ModelInterface walks openAPITypes(), calls the real getters and keys the result by
attributeMap() — the same mechanism already used for JSON request bodies. Query and body
serialization therefore share one code path, and this keeps working for any future model without
further special-casing. Plain arrays and scalars keep the original (array) cast, so nothing else
changes.

sanitizeForSerialization() returns an object at every level, while the $flattenArray step below
dispatches on is_array(), so the object graph is converted to arrays first via a small recursive
toArrayRecursive() helper. A shallow (array) cast is not sufficient: nested models stay objects
and later fail with Object of class stdClass could not be converted to string.


Summary by cubic

Fix query serialization for object and model-typed parameters when the value is a generated model. Models now serialize via getters instead of a shallow array cast, producing correct deepObject and form query strings. Fixes #24684.

  • Bug Fixes
    • Treat any model value as an object (even when typed by its class) and serialize via sanitizeForSerialization() with a recursive toArrayRecursive().
    • Preserve existing behavior for arrays/scalars; only models change.
    • Tests cover model-typed and non-model params, nested models, and arrays; unify PHPUnit test paths.

Written for commit e89ccac. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread samples/client/echo_api/php-nextgen/src/ObjectSerializer.php
Comment thread samples/client/echo_api/php-nextgen/src/ObjectSerializer.php
@wing328
wing328 merged commit cb0d0ee into OpenAPITools:master Aug 12, 2026
28 checks passed
@wing328 wing328 added this to the 7.25.0 milestone Aug 12, 2026
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.

[BUG][php-nextgen] Object-typed query parameter built from a model serializes to the model's internal $container

2 participants