Skip to content

feat: allow restricting operations for parameter attributes on properties#7899

Draft
Maxcastel wants to merge 2 commits intoapi-platform:mainfrom
Maxcastel:feature/allow-restricting-operations-for-parameter-attributes-on-properties
Draft

feat: allow restricting operations for parameter attributes on properties#7899
Maxcastel wants to merge 2 commits intoapi-platform:mainfrom
Maxcastel:feature/allow-restricting-operations-for-parameter-attributes-on-properties

Conversation

@Maxcastel
Copy link
Copy Markdown
Contributor

@Maxcastel Maxcastel commented Mar 31, 2026

Q A
Branch? main
Tickets Related to #7870 (closes #6245)
License MIT
Doc PR api-platform/docs#2281

Requires #7870

#[ApiResource(
    operations: [
        new GetCollection(),
        new Get(),
    ],
)]
class Book
{
    // Applies to all operations
    #[QueryParameter(key: 'search', filter: new PartialSearchFilter())]
    private string $title = '';

    // Applies only to GetCollection
    #[QueryParameter(key: 'name', filter: new PartialSearchFilter(), operations: [new GetCollection()])]
    public string $name = '';

    // Applies only to GetCollection (Patch is not in the list of operations) 
    #[HeaderParameter(key: 'X-Authorization', operations: [new GetCollection(), new Patch()])]
    public string $authToken = '';
}

@Maxcastel Maxcastel changed the title feat: allow Parameter attributes on properties feat: allow restricting operations for parameter attributes on properties Mar 31, 2026
@Maxcastel Maxcastel force-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from 604e56d to b6ba5e3 Compare March 31, 2026 14:20
}

$propertyName = $reflectionProperty->getName();
$key = $parameter->getKey() ?? $propertyName;
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.

no functional test for the default propertyName value can you add one?

$parameter = $attribute->newInstance();

if (
null !== ($parameterOperations = $parameter->getOperations())
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.

not sure about this, how would it work? Should we declare the parameter on all operations or maybe just GetCollection? Or is it that you give an array of operations to the parameter Parameter(operations: [GetCollection::class]) ? I haven't seen any functional test showing this functionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

an array of operations to the parameter Parameter(operations: [GetCollection::class]). The operation must also be declared in the ApiResource operations array.

@Maxcastel Maxcastel force-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from b6ba5e3 to fcd2878 Compare May 1, 2026 00:21
@Maxcastel Maxcastel marked this pull request as draft May 1, 2026 00:38
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.

feat: allow Parameter attributes on properties

2 participants