我在 Laravel 中使用了 l5-swagger,我需要使用不记名令牌进行密室授权 但是当我设置不记名令牌并尝试使用此令牌的 API 时,swagger 返回此错误:
"darkaonline/l5-swagger": "^8.5", “zircote/swagger-php”:“^4.8”
TypeError: P.forEach is not a function
at applySecurities (build-request.js:106:12)
at buildRequest (build-request.js:16:9)
at Object.execute_buildRequest [as buildRequest] (index.js:249:11)
at actions.js:454:24
at index.js:174:16
at redux.mjs:331:12
at wrap-actions.js:33:10
at Object.newAction (system.js:175:26)
at Object.executeRequest (system.js:487:17)
at actions.js:501:22
(anonymous) @ system.js:490
(anonymous) @ actions.js:501
(anonymous) @ index.js:174
(anonymous) @ redux.mjs:331
(anonymous) @ wrap-actions.js:9
newAction @ system.js:175
(anonymous) @ system.js:487
handleValidationResultPass @ execute.jsx:66
handleValidationResult @ execute.jsx:80
onClick @ execute.jsx:90
....
这是我的 l5-swagger 配置
'securityDefinitions' => [
'securitySchemes' => [
/*
* Examples of Security schemes
*/
'sanctum' => [ // Unique name of security
'securityDefinition' => "Bearer",
'type' => 'apiKey', // Valid values are "basic", "apiKey" or "oauth2".
'description' => 'Enter token in format (Bearer <token>)',
'name' => 'Authorization', // The name of the header or query parameter to be used.
'in' => 'header', // The location of the API key. Valid values are "query" or "header".
],
],
'security' => [
/*
* Examples of Securities
*/
[
'sanctum' => []
/*
'oauth2_security_example' => [
'read',
'write'
],
'passport' => []
*/
],
],
],
这是我在控制器中使用的 OA 注释:
/**
* @OA\Post(
* path="/manager/user/add",
* tags={"Manager"},
* security={"sanctum": {}},
* @OA\Response(response="200", description="An example resource",@OA\JsonContent()),
* @OA\Response(response="401", description="unAutosize",@OA\JsonContent()),
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"name", "email","password"},
* @OA\Property(
* property="name",
* type="string",
* ),
* @OA\Property(
* property="email",
* type="string",
* ),
* @OA\Property(
* property="password",
* type="string"
* )
* )))
* )
*/
我找到了解决这个问题的另一种方法:
您可以在Controller.php中使用此注释
/**
* @OA\Info(
* title="Project API",
* version="0.1",
* )
* @OA\SecurityScheme(
* type="http",
* securityScheme="bearerAuth",
* scheme="bearer",
* bearerFormat="JWT"
* )
*/
然后在你的 api 控制器中写下:
/**
* @OA\Post(
* path="/manager/user/add",
* tags={"Manager"},
* security={{"bearerAuth":{}}},
* .
* .
* )
*/