Search code examples
phpsymfonyswaggeropenapiswagger-php

Open API/Swagger Symfony Annotations?


I'm trying to setup Open API 2 (fka swagger) using swagger-php but i haven't been able to find an example of a implementation using annotations with Content-Type: application/x-www-form-urlencoded

Only yaml examples, like the following

Taking from that example, if i have the endpoint

POST https://url.co.uk
Host: server.example.com
Authorization: Bearer <Initial Access Token>
Content-Type: application/x-www-form-urlencoded

&grant_type=password
&client_id=<client id>
&client_secret=<client secret>

How can this be expressed on Open Api annotations for a Symfony/PHP project?


Solution

  • From https://github.com/zircote/swagger-php/blob/2.x/Examples/petstore.swagger.io/controllers/PetController.php#L228

    @SWG\Post(
        consumes={"application/x-www-form-urlencoded"},
        produces={"application/xml", "application/json"},
    )
    

    Or, if you currently use 3-d version, from https://github.com/zircote/swagger-php/blob/master/Examples/petstore.swagger.io/controllers/PetController.php#L241

    @OA\RequestBody(
         *       required=false,
         *       @OA\MediaType(
         *           mediaType="application/x-www-form-urlencoded"
         *       )
         *   ),