'The collectionOperations of API Platform remove the POST route [duplicate]

I begin with API platform and I noticed that when I write my "collectionOperations" in my "personnes" entity, the POST route is removed from the swagger. (same for my route which get all "personnes").

In my entity (with attribute) :

#[ApiResource(
collectionOperations: [
    'me' => [
        'pagination_enabled' => false,
        'path' => '/me',
        'method' => 'get',
        'controller' => MeController::class,
    ]
],
normalizationContext: ['groups' => ['read:User']]

]

Someone can tel me how I can get it back or know why it's removed ?



Solution 1:[1]

I think it’s because you define a collectionOperations. If you define collectionOperations like you did with GET /me you override the default behavior and you need to define POST and GET too.

#[ApiResource(
collectionOperations: [
   'me' => [
    'pagination_enabled' => false,
    'path' => '/me',
    'method' => 'get',
    'controller' => MeController::class,
    ], 
    'get',
    'post'
]

From documentation: “If no operation is specified, all default CRUD operations are automatically registered”

It’s the case for the itemOperation, you didn’t define operation and they all (GET,PUT,DELETE) appears in swagger.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Smaïne