Skip to content

feat!: throw exception when an operation is not declared in ApiResource for parameter attributes on properties - #8552

Open
Maxcastel wants to merge 1 commit into
api-platform:mainfrom
Maxcastel:feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties
Open

Maxcastel wants to merge 1 commit into
api-platform:mainfrom
Maxcastel:feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties

Conversation

@Maxcastel

@Maxcastel Maxcastel commented Sep 21, 2026

Copy link
Copy Markdown
Contributor
Q A
Branch? main
Tickets Related to #7870 & #7899
License MIT
Doc PR api-platform/docs#2346

Follow-up of #7870 and #7899.

#[QueryParameter] / #[HeaderParameter] declared on a property can be restricted to a list of operations. Until now, listing an operation that was not declared in #[ApiResource] was silently ignored: the parameter still applied to the declared operations of the list, and the undeclared one had no effect at all. When none of the listed operations were declared, the parameter simply never applied to anything.

#[ApiResource(
    operations: [
        new GetCollection(),
        new Get(),
    ],
)]
class Book
{
    // Before this PR: applied to GetCollection, the Patch entry was silently ignored
    #[HeaderParameter(key: 'X-Authorization', operations: [new GetCollection(), new Patch()])]
    public string $authToken = '';
}

It now throws a RuntimeException while building the metadata:

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

@Maxcastel Maxcastel changed the title feat!: throw exception when an operation is not delared in ApiResource for for parameter attributes on properties feat!: throw exception when an operation is not declared in ApiResource for for parameter attributes on properties Sep 21, 2026
@Maxcastel
Maxcastel force-pushed the feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties branch from c1bc880 to 162f98e Compare September 21, 2026 13:30
@Maxcastel

Copy link
Copy Markdown
Contributor Author

Not sure whether it's better to throw an exception when an operation is listed in a parameter but is not declared on the resource, or to silently ignore it. Proposing this approach just in case.

@Maxcastel Maxcastel changed the title feat!: throw exception when an operation is not declared in ApiResource for for parameter attributes on properties feat!: throw exception when an operation is not declared in ApiResource for parameter attributes on properties Sep 21, 2026
@Maxcastel
Maxcastel force-pushed the feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties branch from 162f98e to 8c280f7 Compare September 21, 2026 14:07
@Maxcastel
Maxcastel force-pushed the feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties branch from 8c280f7 to 8c0bbed Compare September 21, 2026 14:10
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