我正在运行一个快速
/节点应用程序,并使用“swagger-ui-express”记录我的 api:“^4.5.0”,
。我已经设置了一个要求,即需要将所有请求一起发送到我的 API 中的任何endpoint的 jsonwebtoken
持有者令牌。
我已经加载了swagger文档并正常工作,但现在,当我想知道如何通过授权:Bearer时
如何将持有者令牌发送到从 swagger UI 发送的请求?
在app.js中,我有一个在localhost中正确加载的路由
// Single entry point for swagger docs
router.use(
'/swaggerDocs',
swaggerDoc.serve,
swaggerDoc.setup(swaggerDocumentation),
);
swagger上面的
代码片段(配置文件)中的文档。
import getCountryRegions from './getCountryRegions.doc.js';
export default {
openapi: '3.0.3',
info: {
title: 'Node/express rest api app',
version: '0.0.1',
},
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
in: 'header',
name: 'Authorization',
description: 'Bearer Token',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
},
security: {
bearerAuth: [],
},
servers: [
{
url: 'http://localhost:3010/api',
description: 'Local server',
},
],
paths: {
...getCountryRegions,
},
};
我想通了问题...安全
属性必须有一个 []
环绕其对象。
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
in: 'header',
name: 'Authorization',
description: 'Bearer token to access these api endpoints',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
},
security: [
{
bearerAuth: [],
},
],
这段代码有效。