Skip to content

"Route already described" #39

@federicojasson

Description

@federicojasson

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:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions