Skip to content

fix(symfony): support repeated global parameter classes - #8451

Open
nozarashi20 wants to merge 3 commits into
api-platform:4.3from
nozarashi20:fix/global-default-parameters
Open

fix(symfony): support repeated global parameter classes#8451
nozarashi20 wants to merge 3 commits into
api-platform:4.3from
nozarashi20:fix/global-default-parameters

Conversation

@nozarashi20

@nozarashi20 nozarashi20 commented Aug 13, 2026

Copy link
Copy Markdown
Q A
Branch? 4.3
Tickets Refs #8315
License MIT
Doc PR api-platform/docs#2319

This PR fixes repeated global default parameters in the Symfony integration.

Named entries can now specify their parameter class explicitly, allowing multiple parameters to use the same class while preserving the existing class-keyed configuration syntax.

For example:

api_platform:
    defaults:
        parameters:
            api_token:
                class: ApiPlatform\Metadata\HeaderParameter
                key: API-Token

            request_id:
                class: ApiPlatform\Metadata\HeaderParameter
                key: Request-ID

Allow named global parameter entries with an explicit class while
preserving the legacy class-keyed configuration.
->children()
->scalarNode('class')
->cannotBeEmpty()
->info('The parameter class for a named global parameter entry.')

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.

needs a default to QueryParameter so this doesn't break existing usage.

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.

What existing usage do you have in mind ? Named entries are new in this PR, and the existing class-keyed syntax still works as before.

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.

oh right my bad I thought that it'd have failed but after checking Symfony config just ignores it

A named global default parameter entry (a key that is not a Parameter
subclass) now builds a QueryParameter when no "class" is given, instead
of being silently dropped.

The entry name is resolved before config["class"] on purpose: a
class-keyed entry must keep its own class. Defaulting the "class"
config node instead would inject QueryParameter into every entry and
silently rewrite existing HeaderParameter: entries.
RepeatedDefaultParametersTest was the only file in tests/Functional
without a namespace, breaking the ApiPlatform\Tests\ PSR-4 rule, and
declared its kernel inline instead of tests/Fixtures/app/.
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