-
-
Notifications
You must be signed in to change notification settings - Fork 932
Description
API Platform version(s) affected: 3.0.5
Description
Named operations not working after upgrade to 3.0.5
How to reproduce
#[
ApiResource(
shortName: 'User',
operations: [
new Post(
uriTemplate: '/password/reset',
openapiContext: [
'summary' => 'Create and send password reset token.',
],
denormalizationContext: ['groups' => [PasswordResource::RESET], ],
name: 'password_reset',
),
new Post(
uriTemplate: '/password/set',
openapiContext: [
'summary' => 'Set new password after token has been validated and stored in session.',
],
denormalizationContext: ['groups' => [PasswordResource::SET], ],
name: 'password_set',
),
new Get(
uriTemplate: '/password/reset/{token}',
openapiContext: [
'summary' => 'Validate password reset token and store in session.',
],
name: 'password_reset_token',
),
],
routePrefix: '/users',
stateless: false,
normalizationContext: ['groups' => [PasswordResource::RESET_TOKEN]],
denormalizationContext: ['groups' => [PasswordResource::RESET, PasswordResource::SET]],
paginationEnabled: false,
provider: PasswordDataProvider::class,
processor: PasswordDataProcessor::class,
)
]
class PasswordResource
As far as I can debug (I'm new to api platform, so I can't really tell what is wrong here), it has something to do with ApiPlatform\Metadata\Resource\Factory\OperationDefaultsTrait
or something before it is used. It fails in private function getOperationWithDefaults(ApiResource $resource, Operation $operation, bool $generated = false): array
function on if (!$operations->has($operation->getName())) {
line.
Before 3.0.5 incoming ApiResource $resource
had defined operations array with keys 0, 1, 2, ... etc, but as of 3.0.5 incoming resource has operations array with already defined names like password_set, password_reset etc, which fails this name check function as there can't be two routes with same name.
If I don't define name property, it generates routes as expected but then I can't tell operations apart in processor nor generate path to named route.
Additional Context
Worked before 3.0.5