Skip to content

fix(metadata): do not mutate parameters shared between operations - #8622

Open
Maxcastel wants to merge 2 commits into
api-platform:5.0from
Maxcastel:fix/parameters-shared-between-operations
Open

Maxcastel wants to merge 2 commits into
api-platform:5.0from
Maxcastel:fix/parameters-shared-between-operations

Conversation

@Maxcastel

Copy link
Copy Markdown
Contributor
Q A
Branch? 5.0
Tickets n/a
License MIT
Doc PR n/a

The resource parameters are copied to every operation by reference, and ParameterResourceMetadataCollectionFactory then adds the operation-specific parameters to that shared Parameters instance. The first processed operation pollutes all the others, so operations: on a parameter attribute is ignored as soon as the resource declares parameters. Same fix as #8378 for the runtime providers: clone before mutating.

Before

#[ApiResource(
    operations: [
        new Get(),
        new GetCollection(),
    ],
    parameters: ['q' => new QueryParameter()],
)]
class Book
{
    #[QueryParameter(operations: [new GetCollection()])]
    public string $title = '';
}

title is also declared on Get (and documented on the item operation), and on the resource itself.

After

title is only declared on GetCollection; q is still declared on both operations.

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