Skip to content

fix(openapi): correct parameter name when QueryParameter remaps a filter property#8377

Closed
rodnaph wants to merge 1 commit into
api-platform:4.3from
rodnaph:fix/openapi-query-parameter-property-remap
Closed

fix(openapi): correct parameter name when QueryParameter remaps a filter property#8377
rodnaph wants to merge 1 commit into
api-platform:4.3from
rodnaph:fix/openapi-query-parameter-property-remap

Conversation

@rodnaph

@rodnaph rodnaph commented Jul 1, 2026

Copy link
Copy Markdown
Q A
Branch? 4.3
Tickets None
License MIT
Doc PR None

When a QueryParameter uses property to remap a filter's property name (e.g. order[sort_by] mapped to property rating), OpenApiFactory used str_replace(, , ) to rewrite the filter description key. Because both the description key (order[rating]) and the replacement key (order[sort_by]) share the order[...] wrapper, the naive str_replace produced order[order[sort_by]].

The fix is to skip filter description entries that don't match the mapped property and use the QueryParameter key directly as the parameter name.

Workaround

Register two #[ApiFilter] attributes per resource:

  1. One without alias — enters the operation's filter list and generates correct OpenAPI/Hydra docs via the standard path
  2. One with alias — referenced by the QueryParameter for actual filter invocation

The QueryParameter sets openApi: false and hydra: false to suppress the auto-generated entries.

…ter property

When a QueryParameter uses `property` to remap a filter's property name
(e.g. `order[sort_by]` mapped to property `rating`), OpenApiFactory used
`str_replace(, , )` to rewrite the filter description key.
Because both the description key (`order[rating]`) and the replacement
key (`order[sort_by]`) share the `order[...]` wrapper, the naive
str_replace produced `order[order[sort_by]]`.

Fix: skip filter description entries that don't match the mapped property
and use the QueryParameter key directly as the parameter name.
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ApiFilter(OrderFilter::class, alias: 'product_order_filter', properties: ['rating'])]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ApiFilter will get deprecated/removed, did you try specifying the filter inside the QueryParameter instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah that's simpler, thanks!

Apologies for the distraction.

@rodnaph rodnaph closed this Jul 2, 2026
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