nav*_*een 2 node.js swagger swagger-ui
我正在尝试使用 Node.js Express 服务器向 Swagger UI 添加授权标头。请求需要x-auth-token作为 API 的标头之一才能进行身份验证。下面是我的app.js代码:
const swaggerDefinition = {
info: {
title: 'MySQL Registration Swagger API',
version: '1.0.0',
description: 'Endpoints to test the user registration routes',
},
host: 'localhost:8000',
basePath: '/api/v1',
securityDefinitions: {
bearerAuth: {
type: 'apiKey',
name: 'x-auth-token',
scheme: 'bearer',
in: 'header',
},
},
};
const options = {
// import swaggerDefinitions
swaggerDefinition,
// path to the API docs
apis: ['dist-server/docs/*.yaml'],
};
// initialize swagger-jsdoc
const swaggerSpec = swaggerJSDoc(options);
// use swagger-Ui-express for your app documentation endpoint
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
Run Code Online (Sandbox Code Playgroud)
但这并没有将标头添加到 Swagger UI 中的请求中。如何解决这个问题?
将以下键添加到您的swaggerDefinition:
security: [ { bearerAuth: [] } ],
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2117 次 |
| 最近记录: |