Skip to content

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

Merged
soyuka merged 1 commit into
api-platform:5.0from
Maxcastel:feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties
Sep 28, 2026
Merged

soyuka merged 1 commit into
api-platform:5.0from
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? 5.0
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.

#[ApiResource(
    operations: [
        new GetCollection(),
        new Get(),
    ],
)]
class Book
{
    // Before this PR: applied to GetCollection, the Patch 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 3 times, most recently from 8c0bbed to 5185d55 Compare September 25, 2026 15:28
@soyuka

soyuka commented Sep 25, 2026

Copy link
Copy Markdown
Member

I like this I'm wondering if we couldn't put this on 5.0 though, wdyt?

@Maxcastel

Copy link
Copy Markdown
Contributor Author

Yes, this should have been part of 5.0, as it should have been included in #7899 (it was an oversight). But now that 5.0 has been released, it would cause a BC.

@soyuka

soyuka commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

target 5.0 then :) its a bug fix on our feature

@Maxcastel
Maxcastel changed the base branch from main to 5.0 September 28, 2026 13:28
@Maxcastel
Maxcastel force-pushed the feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties branch from 5185d55 to 8de77f1 Compare September 28, 2026 13:42
@Maxcastel
Maxcastel force-pushed the feat/throw-operation-not-declared-in-ApiResource-for-parameter-attributes-on-properties branch from 8de77f1 to defd989 Compare September 28, 2026 13:44
@Maxcastel Maxcastel changed the title feat!: throw exception when an operation is not declared in ApiResource for parameter attributes on properties fix: throw exception when an operation is not declared in ApiResource for parameter attributes on properties Sep 28, 2026
@Maxcastel

Copy link
Copy Markdown
Contributor Author

Done @soyuka

@soyuka
soyuka merged commit d25771a into api-platform:5.0 Sep 28, 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