Swagger doctrine/zircote 承载授权码

Swagger doctrine/zircote bearer Authorization code

我正在尝试使用 swagger zircote 来创建 swagger ui json。 对于我的应用程序,我使用 JWT,我需要在我的 json:

中使用以下 swagger 代码
"securityDefinitions": {
    "Bearer": {
      "in": "header",
      "type": "accessToken",
      "name": "Authorization"
    }
},

但我不知道如何使用 swaggers zircote 创建该代码。我试过以下代码:

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

但这会导致以下错误:

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

谁能帮我,我找不到任何关于这个的好文档,也许是具体的,但我希望有人能帮助我。

谢谢!

也在 github...https://github.com/zircote/swagger-php/issues/366

上发布

使用 @SWG\SecurityScheme 而不是 @SWG\SecurityDefinitions

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

可在 vendor/zircote/swagger-php/src/Annotations

中找到可用注释的列表

在我的案例中工作如下:

在src目录下class(一些常规设置):

#[OA\Info(version: "0.1", title: "My First API")]
#[OA\Server(url: 'http://localhost:8080/api')]
#[OA\SecurityScheme(
    securityScheme: 'bearerAuth',
    type: 'http',
    in: 'header',
    scheme: 'bearer',
)]
class OpenApi
{
}

和端点:

#[OA\Get(
    path: '/someUrl',
    summary: 'some description',
    security: [['bearerAuth' => []]],
    tags: ['some tag'],
)
]
#[OA\Response(response: '200', description: 'The data 1')]
#[OA\Response(response: '401', description: 'Unauthorized')]
public function getSomeData($request, $response, $args)