Search code examples
phpdoctrineswaggerjwtbearer-token

Swagger doctrine/zircote bearer Authorization code


i'm trying to use swagger zircote to create the swagger ui json. for my application i use JWT and i need the following swagger code in my json:

"securityDefinitions": {
    "Bearer": {
      "in": "header",
      "type": "accessToken",
      "name": "Authorization"
    }
},

But i dont know how i create that code with swaggers zircote. I've tried the following code:

 * @SWG\Swagger(
 *     schemes={"https"},
 *     @SWG\SecurityDefinitions(
 *         bearer={
 *             type="apiKey",
 *             name="Authorization",
 *             in="header"
 *         }
 *     ),

but this results in the following error:

The annotation "@Swagger\Annotations\SecurityDefinitions" in .\index.php on line 2 does not exist, or could not be auto-loaded.

Can someone help me, i cant find any good documentation about this, maybe its to specific, but i hope someone can help me.

Thanks!

Issued this also on the github... https://github.com/zircote/swagger-php/issues/366


Solution

  • Use @SWG\SecurityScheme instead of @SWG\SecurityDefinitions.

     * @SWG\Swagger(
     *     schemes={"https"},
     *     @SWG\SecurityScheme(
     *         securityDefinition="Bearer",
     *         type="apiKey",
     *         name="Authorization",
     *         in="header"
     *     ),
    

    A list of available annotations can be found list in vendor/zircote/swagger-php/src/Annotations