我在swagger UI中有一些端点必须是私有的,而某些端点是公共的,可以通过键入“ domain / private / api-docs”(私有)和“ domain / api-docs”(公共)来访问。在升级swagger UI之前,此方法运行良好。
const swaggerPublicOptions =
{ swaggerDefinition:
{ swagger: '2.0'
, basePath: `/v1`
}
, apis:
[
// routes here
]
};
const swaggerSpec = swaggerJSDoc(swaggerPublicOptions);
this.app.get('/swagger.json', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
const swaggerOptions =
{ swaggerDefinition:
{ swagger: '2.0',
basePath: `/v1`
}
, apis:
[
// routes here
]
};
const swaggerPrivateSpec = swaggerJSDoc(swaggerOptions);
this.app.get('/swagger.private.json', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerPrivateSpec);
});
this.app.use('/private/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerPrivateSpec, true, customOptions));
this.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec,options));