How can i write this JSON swagger-php below with annotations?

760 Views Asked by At

I'm using OpenAPI 3.0 to document my Symfony API. this is the JSON code that authenticates the user to send requests:

"securitySchemes": {
        "Bearer": {
            "type": "http",
            "description": "Entrer le token JST",
            "scheme": "bearer",
            "bearerFormat": "JWT"
        }
    }
},
"security": [
    {
        "Bearer": []
    }
]

How can i write this with annotations in controller ?

thanks

1

There are 1 best solutions below

0
DerManoMann On

You almost can; currently swagger-php does not support the bearerFormat property.

=> https://github.com/zircote/swagger-php/issues/1258

The rest would look something like this globally.

/**
 *     @OA\SecurityScheme(
 *         securityScheme="bearerAuth",
 *         type="http",
 *         scheme="bearer",
 *         description="Entrer le token JST"
 *     )
 */

For a controller to require security you'd add this:

/**
 * @OA\Get(
 *     path="/api/endpoint",
 *     ...
 *     security={{ "bearerAuth": {} }}
 * )
 */