Mayor of the Plattenbaus
Mayor of the Plattenbaus

Reputation: 1256

API Platform: Change description of an endpoint

I have created a custom endpoint using API Platform. Here is the annotation I have used:

/**
 * We only want the POST option for now.
 *
 * @ApiResource(
 *      itemOperations={},
 *      collectionOperations={"post"={
 *           "method"="POST",
 *           "controller"=PairingController::class,
 *           "path"="/devices/pairing",
 *           "defaults"={"_api_receive"=false}
 *     }},
 * )
 *
 *
 */
class Pairing
{
...

The controller I am calling executes some custom logic. I am happy with how things are working so far. But the documentation generated by API Platform is now inaccurate. It says:

/devices/pairing Creates a Pairing resource.

... which is no longer true, since my controller does not generate a pairing. (It calls out to a different API instead, asking that API to do some stuff.)

So here's my question: How do I change my annotation to allow me to write a custom piece of documentation for this endpoint?

Upvotes: 3

Views: 4663

Answers (2)

Lenny4
Lenny4

Reputation: 1668

For ApiPlatform > 2.6

You need to use ApiPlatform\Metadata\ApiProperty, as shown here https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts

For ApiPlatform <= 2.6

It didn't works for me, here is how I did it with openapi_context:

"openapi_context"={
    "summary"="test",
},

Upvotes: 4

K&#233;vin Dunglas
K&#233;vin Dunglas

Reputation: 3024

You can use the swagger_context key to change any Swagger field, including description (the one you are looking for): https://api-platform.com/docs/core/swagger/#changing-operations-in-the-swagger-documentation

Upvotes: 3

Related Questions