Closed lynchs61 closed 2 years ago
Nevermind. I figured it out and it was a misunderstanding I had with express routing. So I'll post it here in case anyone else runs into something similar.
I just thought that express would magically know that the incoming parameter should be an integer. But this is obviously not the case. So I had to add the following extra middleware to the route to first try to parse the parameter as an integer before it gets to the validator.
const convertSequenceToInt = (req, res, next) => {
req.params.sequence = parseInt(req.params.sequence, 10);
next();
};
Then my route is setup as follows with the conversion middleware before the validator:
// routes/tick.js
router.get('/:sequence', [convertSequenceToInt, validator.validate('get', '/v1/tick/{sequence}')], (req, res, next) => {
// Get the tick from DB and return
});
And now everything works as expected and is validated correctly.
I'm having trouble getting a correct validation for a parameter in path. I have the following in my API spec.
And this is the setup of my express router:
But when I make a call to the endpoint like this:
I get the following error saying that the parameter must be an integer:
Is this a bug? Or am I missing something important here?