feat: allow restricting operations for parameter attributes on properties#7899
Conversation
604e56d to
b6ba5e3
Compare
| } | ||
|
|
||
| $propertyName = $reflectionProperty->getName(); | ||
| $key = $parameter->getKey() ?? $propertyName; |
There was a problem hiding this comment.
no functional test for the default propertyName value can you add one?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
an array of operations to the parameter Parameter(operations: [GetCollection::class]). The operation must also be declared in the ApiResource operations array.
b6ba5e3 to
fcd2878
Compare
fcd2878 to
f0ca1fd
Compare
f0ca1fd to
21cfe04
Compare
21cfe04 to
16dcdbb
Compare
16dcdbb to
a1eb284
Compare
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 = ''; }