API-Platform Opération personnalisée

Par youstra, il y a 6 ans


Bonjour !

J'utilise API Platform depuis quelques jours maintenant (moins d'un mois). Et je veux savoir comment l'on peut créer une opération personnalisée comme à l'ancienne avec Symfony :

4 réponses

olive140, il y a 6 ans

Bonjour,

Tu peut créer un controller avec une route comme à l'ancienne et si tu veux la documentation c'est expliqué ici :
https://api-platform.com/docs/core/swagger/

Moi par exemple j'ai aujouté deux routes pour le token et le refresh token.

youstra, il y a 6 ans

Merci pour ta réponse. Mais je ne sais pas exactement comment m'y prendre.
Dans quel fichier dois-je mettre la config décrite ici https://api-platform.com/docs/core/swagger/#changing-operations-in-the-openapi-documentation:

resources: App\Entity\Rabbit: collectionOperations: create_user: method: get path: '/rabbit/rand' controller: App\Controller\RandomRabbit # if you are using OpenApi V3 use 'openapi_context' instead of 'swagger_context' swagger_context: summary: Random rabbit picture description: > # Pop a great rabbit picture by color! ![A great rabbit](https://rabbit.org/graphics/fun/netbunnies/jellybean1-brennan1.jpg) parameters: - in: body schema: type: object properties: name: {type: string} description: {type: string} example: name: Rabbit description: Pink rabbit

En plus de cela, il y a un autre problème que je rencotre. Mais je vais créer un nouveau sujet pour ça

youstra, il y a 6 ans

Excuse moi beaucoup mais je ne comprends toujours pas.
Quand je place ce code

resources: App\Entity\Rabbit: collectionOperations: create_user: method: get path: '/rabbit/rand' controller: App\Controller\RandomRabbit # if you are using OpenApi V3 use 'openapi_context' instead of 'swagger_context' swagger_context: summary: Random rabbit picture description: > # Pop a great rabbit picture by color! ![A great rabbit](https://rabbit.org/graphics/fun/netbunnies/jellybean1-brennan1.jpg) parameters: - in: body schema: type: object properties: name: {type: string} description: {type: string} example: name: Rabbit description: Pink rabbit

dans config/services.yaml, j'ai une erreur. C'est pareil lorsque je le mets dans config/packages/api_platform.yaml. Et même en créant un fichier config/resouces.yaml, je n'ai pas satisfaction.
La documentation officielle aussi ne dit pas à quel endroit mettre ce code.