Swagger openAPI注释中的“授权:承载<令牌>”问题

时间:2019-03-08 09:42:22

标签: php swagger openapi swagger-php

我使用这些软件包(通过composer安装)

  

“ swagger-api / swagger-ui”:“ ^ 3.0”,
  “ zircote / swagger-php”:“〜2.0 | 3。*”

在我的def控制器中,我有这些注释

/**
 * @OA\Info(title="My API", version="0.1")
 * @OA\Schemes(format="http")
 * @OA\SecurityScheme(
 *      securityScheme="bearerAuth",
 *      in="header",
 *      name="Authorization",
 *      type="http",
 *      scheme="Bearer",
 *      bearerFormat="JWT",
 * ),
 * @OA\Tag(
 *     name="Auth",
 *     description="Auth endpoints",
 * )
 * @OA\Tag(
 *     name="Users",
 *     description="Users endpoints",
 * )
 */
class Controller extends BaseController

然后我有方法

/**
 * 
 * @OA\Get(
 *      path="/users",
 *      operationId="getListOfUsers",
 *      tags={"Users"},
 *      description="Get list of users",
 *      security={{"bearerAuth":{}}}, 
 *      @OA\Parameter(
 *         name="Authorization",
 *         in="header",
 *         required=true,
 *         description="Bearer {access-token}",
 *         @OA\Schema(
 *              type="bearerAuth"
 *         ) 
 *      ), 
 *      @OA\Response(
 *          response=200,
 *          description="Get list of users.",
 *          @OA\JsonContent(type="object",
 *              @OA\Property(property="message", type="string"),
 *              @OA\Property(property="data", type="array",
 *                  @OA\Items(type="object",
 *                      @OA\Property(property="id", type="integer"),
 *                      @OA\Property(property="name", type="string"),
 *                      @OA\Property(property="email", type="string"),
 *                  ),
 *              ),
 *          ),
 *       ),
 *       @OA\Response(response=401, description="Unauthorized"),
 *       @OA\Response(response=404, description="Not Found"),
 * )
 * 
 * @return JsonResponse
 */
public function users()

因此,当我尝试通过swagger ui测试此路由时,我遇到了错误

  

401,“消息”:“未经身份验证”。

当我检查标题(Firefox)时,我没有看到

  

授权:承载{{access-token}}

但是我有我的令牌

  

Cookie:XSRF-TOKEN = eyJpdiI6Ik5COUV5Y1ltRTM4eXNsRlpLY2ptTGc9PSIsInZhbHVlIjoiNDFCbG95c1RHSHRFT0IyWWZ4aWFRQVJ6RHhh1hmmR1RmR4MQ1YR1RTM4eXN2R1MQ1Y1M

Swagger UI无法正确发送标头。注释有什么问题?谢谢

0 个答案:

没有答案