Я дал версионный свой API для проекта.поэтому у него есть две папки v1 и v2, которые имеют разные apis.Теперь в ordrer для реализации swagger для v1 и v2 я написал следующий код в app.js .
// Swagger definition
// You can set every attribute except paths and swagger
const swaggerDefinition = {
swagger: '2.0',
info: {
// API informations (required)
title: 'API', // Title (required)
version: '1.0.0', // Version (required)
description: 'Used for api documentation', // Description (optional)
},
host: `localhost:3000`, // Host (optional)
basePath: '/v1', // Base path (optional)
};
// Options for the swagger docs
const optionsV1 = {
// Import swaggerDefinitions
swaggerDefinition,
// Path to the API docs
// Note that this path is relative to the current directory from which the Node.js is ran, not the application itself.
apis: ['./app/v1/docs/*.yaml']
};
const optionsV2 = {
// Import swaggerDefinitions
swaggerDefinition,
// Path to the API docs
// Note that this path is relative to the current directory from which the Node.js is ran, not the application itself.
apis: ['./app/v2/docs/*.yaml']
};
optionsV2.swaggerDefinition.basePath = "/v2"
// Initialize swagger-jsdoc -> returns validated swagger spec in json format
const swaggerSpecV1 = swaggerJSDoc(optionsV1);
const swaggerSpecV2 = swaggerJSDoc(optionsV2);
// const swaggerDocument = require('./app/v1/docs/swagger.json');
// app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpecV1));
app.use('/v2/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpecV2));
, но если я нажал URL-адрес как / v1 / docs или / v2 / docs это всегда показывает мне api doc для v2 .последняя строка, написанная здесь для v2 , так что она всегда показывает документ только для v2.Подскажите пожалуйста, как поддержать несколько API?