如何解决Node.js Swagger无法向请求添加授权标头
我正在尝试使用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));
但是,这并未将标头添加到Swagger UI中的请求中。如何解决此问题?
解决方法
将以下密钥添加到您的 try:
return self[key]
except KeyError: # <---- KeyError raised in __missing__ caught here
return default
:
swaggerDefinition
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。