Skip to content

fix(doctrine): honor castToArray and schema in filter OpenAPI parameters#8423

Open
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/8406-openapi-filter-schema-and-casttoarray
Open

fix(doctrine): honor castToArray and schema in filter OpenAPI parameters#8423
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/8406-openapi-filter-schema-and-casttoarray

Conversation

@soyuka

@soyuka soyuka commented Jul 26, 2026

Copy link
Copy Markdown
Member
Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Fixes #8406
License MIT
Doc PR n/a

What

OpenApiFilterTrait::getOpenApiParameters() (used by ExactFilter, PartialSearchFilter, IriFilter, SortFilter, OrFilter) had two problems:

  1. It returned a singular parameter whenever a scalar schema was set, ignoring castToArray — so castToArray: true produced a singular parameter, and the default (null → both singular + array) was never reached for scalar-typed parameters.
  2. The singular OpenApiParameter was built without its declared schema, so an explicit schema: ['type' => 'integer'] was dropped.

castToArray is now the sole control, and the schema is always passed through:

  • castToArray === false → singular only
  • castToArray === true → array only
  • castToArray === null (default) → both
  • the singular parameter carries the declared schema; the array parameter's schema is the declared one when already type: array, else ['type' => 'array', 'items' => <schema>].

Behavior change

A scalar-typed parameter with default castToArray now exposes both key and key[] (previously singular-only when a scalar schema was set). This matches the old SearchFilter behavior and the documented default. Consequence: a boolean ExactFilter with schema: ['type' => 'boolean'] and no castToArray now also emits key[]; set castToArray: false for a single parameter (the docs are being updated accordingly).

Test

ExactFilterSchemaParameterTest asserts the OpenAPI output for the four cases from the issue (scalar + default → both; castToArray: true → array only; castToArray: false → singular only; explicit array schema + castToArray: true → single array, no duplicate). Fails on 2/4 before the fix, all green after. Full tests/Functional/Parameters/ + OpenApiTest suites green; php-cs-fixer clean; PHPStan [OK].

OpenApiFilterTrait::getOpenApiParameters() returned a singular parameter
whenever a scalar schema was set, overriding castToArray, and built the
singular parameter without its declared schema. castToArray is now the sole
control — false: singular, true: array, null: both — and the declared schema
is passed through in every case.

Fixes api-platform#8406
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.

1 participant