我需要能夠將以下按鈕添加到 Swagger 的 UI 界面,以便測驗人員可以添加“Bearer token”標頭并測驗 api。

我招搖的選項定義是:
module.exports = {
definition: {
openapi: "3.0.3",
info: {
title: "APIs",
version: "1.0.0",
},
servers: [
{
url: `http://localhost:${process.env.PORT}`
}
],
securityDefinitions: {
bearerAuth: {
type: 'apiKey',
name: 'Authorization',
scheme: 'bearer',
in: 'header',
},
}
},
apis: ["./routes/*.js", "app.js"],
};
我的端點如下:
/**
* @swagger
* /api/users/test:
* post:
* security:
* - Bearer: []
* summary: test authorization
* tags: [User]
* description: use to test authorization JWT
* responses:
* '200':
* description: success
* '500':
* description: Internal server error
*/
router.post('/test', verifyJWT(), async (req, res) => {
res.send('hi');
})
uj5u.com熱心網友回復:
您使用的是 OAS v3 嗎?你的宣告中有錯誤,例如securityDefinitions現在被呼叫securitySchemes并且它在里面components。
檢查https://swagger.io/docs/specification/authentication/
當您修復架構時,您security將向路徑添加一個屬性以使用安全架構保護它,以便您獲得綠色Authorize按鈕。
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
paths:
/api/users/test:
post:
security:
- BearerAuth: []
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/436900.html
標籤:javascript 节点.js 打字稿 昂首阔步
上一篇:為什么“字串”不能用于索引?
