-
Notifications
You must be signed in to change notification settings - Fork 13
Description
I have the following use case (simplified):
const { getHealth, getHealthMetadata} = require('./health');
const router = Router();
...
router.get('/', getHealth).describe(getHealthMetadata);
router.get('/health', getHealth).describe(getHealthMetadata);
...And health.js:
async function getHealth(req, res) {
return res.status(200).json({
healthy: true
});
}
const getHealthMetadata = {
responses: {
200: {
description: 'Check the API health'
}
}
};
module.exports = {
getHealth,
getHealthMetadata
};So, I'm reusing a controller for two route endpoints.
Since I'm reusing the getHealthMetadata object, I'm getting a console message Route already described, and the second endpoint is not documented in the generated spec. I understand this happens because the describeRouterRoute function sets described as true:
swagger-spec-express/lib/swaggerise.js
Line 99 in d4b2018
| metaData.described = true; |
I was wondering what's the purpose of that property, as I see it's only used in that same function to return early:
swagger-spec-express/lib/swaggerise.js
Line 73 in d4b2018
| if(metaData.described){ |
My proposal is to remove that check, allowing to describe multiple endpoints with the same metadata object. I can work on a PR.
Thanks