Swagger Implementation:
const express = require('express');
const router = express.Router();
const swaggerUi = require('swagger-ui-express');
const swaggerJSDoc = require('swagger-jsdoc');
module.exports = async (app) => {
router.use('/', swaggerUi.serve, swaggerUi.setup(
swaggerJSDoc({
swaggerDefinition: { ...require('../swagger.json') },
apis: ['./app/**/*.js']
}),
{
swaggerOptions: {
displayRequestDuration: true,
docExpansion: "none",
filter: false,
showExtensions: true,
showCommonExtensions: true,
displayOperationId: true
}
}
));
app.use('/api-docs', router); // SET SWAGGER DOCS
}
I have 2 nodejs-express projects and implemented swagger as per above code:
- First Project running in http:localhost:3001
- Second project running in http:localhost:3002
I have third project only for swagger docs, that is running in http:localhost:3000, I want to access both (1), (2) of the projects docs in this third project using explorer for only swagger api docs, but i can not able to access it direct by url of project,
router.use('/', swaggerUi.serve, swaggerUi.setup(
swaggerJSDoc({
swaggerDefinition: { ...require('../swagger.json') }
}),
{
explorer: true,
swaggerOptions: {
displayRequestDuration: true,
docExpansion: "none",
filter: false,
showExtensions: true,
showCommonExtensions: true,
displayOperationId: true,
urls: [
{
url: 'http://localhost:3001',
// url: 'http://localhost:3001/api-docs', // also tried but not working
name: 'Project 1'
},
{
url: 'http://localhost:3002',
// url: 'http://localhost:3002/api-docs', // also tried but not working
name: 'Project 2'
}
]
}
}
));
app.use('/api-docs', router); // SET SWAGGER DOCS
It says failed to load api definition.
Am i doing wrong way or is there any other npm i have to implement for this?