spe*_*zia 6 php swagger swagger-php openapi
我使用这些包(通过作曲家安装)
"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
Run Code Online (Sandbox Code Playgroud)
然后我有方法
/**
*
* @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()
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试通过 swagger ui 测试这条路线时,出现错误
401, "message": "未经身份验证。"
当我检查标题(Firefox)时,我还没有看到
授权:承载 {{access-token}}
但我有我的令牌
Cookie:XSRF-TOKEN=eyJpdiI6Ik5COUV5Y1ltRTM4eXNsRlpLY2ptTGc9PSIsInZhbHVlIjoiNDFCbG95c1RHSHRFT0IyWWZ4aWFRQVJ6RHhTS1A4SFJiQXp2amlWWQsZI3RmRmQQsZI3RmRmQsZI3RhmRhmQcsIlIjoi
Swagger UI 无法正确发送标头。注释有什么问题?谢谢
Ngh*_* Le 11
授权与 XSRF-TOKEN 无关。我也遇到了同样的问题,经过几个小时的谷歌搜索后解决了。以下是您可能想要尝试的更改:
删除这些行:
* @OA\Parameter(
* name="Authorization",
* in="header",
* required=true,
* description="Bearer {access-token}",
* @OA\Schema(
* type="bearerAuth"
* )
* ),
Run Code Online (Sandbox Code Playgroud)
并改变这一点:
* @OA\SecurityScheme(
* securityScheme="bearerAuth",
* in="header",
* name="Authorization",
* type="http",
* scheme="Bearer",
* bearerFormat="JWT",
* ),
Run Code Online (Sandbox Code Playgroud)
到
* @OA\SecurityScheme(
* securityScheme="bearerAuth",
* in="header",
* name="bearerAuth",
* type="http",
* scheme="bearer",
* bearerFormat="JWT",
* ),
Run Code Online (Sandbox Code Playgroud)
请注意,“承载”和“承载”是不同的。