Skip to content

BC break in 4.2 ApiResource is excluded from container #7402

@VincentLanglet

Description

@VincentLanglet

API Platform version(s) affected: 4.2.0

Description
In 4.1 I was using ApiResource on some custom controller to provide doc, for instance:

#[ApiResource(
    shortName: 'Authentication',
    operations: [
        new Post(
            uriTemplate: '/auth/refresh',
            controller: self::class.'::refresh',
            openapi: new Operation(
                tags: ['Authentication'],
                summary: 'Refresh an authentication token',
                description: 'Provides a new token pair in exchange for a valid refresh token.',
            ),
            read: false,
            deserialize: false,
            write: false,
            serialize: false
        ),
    ],
)]

It was working perfectly, but since 4.2 this break the application by excluding the controller from the container.
I'm getting

Operation "_api_/auth/refresh_post" is defining an unknown service as controller "Account\Controller\AuthController". Make sure it is properly registered in the dependency injection container in . (which is being imported from "/app/config/routes/api_platform.yaml"). Make sure there is a loader supporting the "api_platform" type.

How to reproduce
Add ApiResource to a controller or any service.

I understand it might be considered as weird to declare a Controller as resource but it was pretty useful to document some custom controller routes. I'm not sure there is another easy way so far ?

Possible Solution
Removing ->addTag('container.excluded', ['source' => 'by #[ApiResource] attribute']);

Additional Context
Bug introduced in #6943 cc @GromNaN

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions