Skip to content

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

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

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

Conversation

@Maxcastel

@MaxcastelMaxcastel commented Mar 31, 2026

Copy link
Copy Markdown
Contributor
QA
Branch?main
TicketsRelated to #7870 (closes#6245)
LicenseMIT
Doc PRapi-platform/docs#2281

Requires #7870

#[ApiResource(
operations: [
newGetCollection(),
newGet(),
],
)]
class Book
{
// Applies to all operations
#[QueryParameter(key: 'search', filter: newPartialSearchFilter())]
privatestring$title = '';
// Applies only to GetCollection
#[QueryParameter(key: 'name', filter: newPartialSearchFilter(), operations: [newGetCollection()])]
publicstring$name = '';
// Applies only to GetCollection (Patch is not in the list of operations) 
#[HeaderParameter(key: 'X-Authorization', operations: [newGetCollection(), newPatch()])]
publicstring$authToken = '';
}

@MaxcastelMaxcastel changed the title feat: allow Parameter attributes on propertiesfeat: allow restricting operations for parameter attributes on propertiesMar 31, 2026
@Maxcastel
Maxcastelforce-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from 604e56d to b6ba5e3CompareMarch 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?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Good catch! Changing the value of $propertyName did not cause the tests to fail.

Added unit and functional tests in #7870 (https://github.com/api-platform/core/compare/04dd41f03a46783113c0e3c876d6dae2b1d98f93..6947b111887145ee1f777d4be5308499eb42ce09) and rebased on it.

$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
ContributorAuthor

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 ApiResourceoperations array.

@Maxcastel
Maxcastelforce-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from b6ba5e3 to fcd2878CompareMay 1, 2026 00:21
@Maxcastel
Maxcastel marked this pull request as draft May 1, 2026 00:38
@Maxcastel
Maxcastelforce-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from fcd2878 to f0ca1fdCompareMay 2, 2026 21:54
@Maxcastel
Maxcastelforce-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from f0ca1fd to 21cfe04CompareMay 11, 2026 20:41
@Maxcastel
Maxcastelforce-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from 21cfe04 to 16dcdbbCompareMay 11, 2026 22:21
@Maxcastel
Maxcastelforce-pushed the feature/allow-restricting-operations-for-parameter-attributes-on-properties branch from 16dcdbb to a1eb284CompareMay 11, 2026 22:24
@Maxcastel
Maxcastel requested a review from soyukaMay 11, 2026 22:28
@Maxcastel
Maxcastel marked this pull request as ready for review May 11, 2026 22:29
Sign up for freeto 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

@Maxcastel@soyuka