我正在尝试在 swagger 中配置我的 express rest api 文档以使用基本身份验证。为此,我使用 swagger-jsdoc 和 swagger-express-ui 包。这是我目前的招摇配置:
swagger: {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: 'API Documentation',
version: 'v1',
description: 'A REST API Service.',
license: {
name: '',
url: '',
},
contact: {
name: '',
url: '',
email: '',
},
},
servers: [
{
url: 'http://localhost:3000/api/v1',
description: 'Development Server',
},
],
components: {
securitySchemes: {
basicAuth: {
type: 'http',
scheme: 'basic',
description: 'Basic Authroization header.',
},
},
},
security: [
{
basicAuth: [],
},
],
},
apis: ['./src/routes/api-v1/*.js'],
securityDefinitions: {
auth: {
type: 'basic',
},
},
security: [{ auth: [] }],
},