Skip to content

feat(metadata): accept operation class names in parameter operations - #8624

Merged
soyuka merged 1 commit into
api-platform:5.0from
Maxcastel:feat/parameter-operations-class-strings
Oct 12, 2026
Merged

soyuka merged 1 commit into
api-platform:5.0from
Maxcastel:feat/parameter-operations-class-strings

Conversation

@Maxcastel

@Maxcastel Maxcastel commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Branch? main
Tickets n/a
License MIT
Doc PR api-platform/docs#2357

The operations option of parameter attributes on properties only accepts operation instances: passing a class name throws a raw TypeError: Cannot use "::class" on string. Since the restriction matches on the operation class anyway, accept class names too (they can be mixed with instances).

Before

#[ApiResource(operations: [new GetCollection(), new Get()])]
class Book
{
    #[QueryParameter(key: 'search', operations: [GetCollection::class])]
    public string $name = '';
}

TypeError: Cannot use "::class" on string

After

search is only declared on GetCollection. A class name that is not declared on the resource throws the same exception as an instance:

Parameter attribute on property "name" is restricted to the operation "ApiPlatform\Metadata\Patch" which is not declared on the resource "App\Entity\Book".

@Maxcastel
Maxcastel marked this pull request as draft October 1, 2026 15:41
@Maxcastel
Maxcastel marked this pull request as ready for review October 12, 2026 08:52
@Maxcastel
Maxcastel force-pushed the feat/parameter-operations-class-strings branch from 0123828 to ded131b Compare October 12, 2026 09:10
@soyuka
soyuka changed the base branch from main to 5.0 October 12, 2026 14:30
@soyuka
soyuka force-pushed the feat/parameter-operations-class-strings branch from ded131b to 427f769 Compare October 12, 2026 14:35
@soyuka
soyuka merged commit 5bd3b33 into api-platform:5.0 Oct 12, 2026
115 of 117 checks passed
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