swagger-routes
swagger-routes copied to clipboard
Support for restify 7.x and 8.x
We are using this library for all routes on Restify 4.x and 6.x without issues. There is however change in path resolver in restify 7.x and it is causing this issue:
Generated 'api.yml'
13:44:51.878Z FATAL rocket: Uncaught exception, aborting Node (err.code=ERR_ASSERTION)
AssertionError [ERR_ASSERTION]: The first character of a path should be `/` or `*`
at Router.on (...\node_modules\find-my-way\index.js:69:3)
at RouterRegistryRadix.add (...\node_modules\restify\lib\routerRegistryRadix.js:42:21)
at Router.mount (...\node_modules\restify\lib\router.js:212:20)
at Server.serverMethod [as get] (...\node_modules\restify\lib\server.js:1686:33)
at registerDocsRoute (...\node_modules\swagger-routes\src\routeRegister.js:36:7)
at Object.registerRoutes (...\node_modules\swagger-routes\src\routeRegister.js:12:3)
at addHandlers (...\node_modules\swagger-routes\src\index.js:19:17)
It happens ^^ when we call swaggerRoutes(server, {
To see what exactly is happening I logged data from https://github.com/mikestead/swagger-routes/blob/master/src/routeRegister.js#L34
And if I update it with this:
function registerDocsRoute(app, options) {
console.log(`/${options.api.basePath}/${options.docsPath}`)
const docsPath = path.normalize(`/${options.api.basePath}/${options.docsPath}`)
console.log(docsPath);
app.get(docsPath, options.docsMiddleware, function handler(req, res) { res.json(options.api) })
}
Then this is logged before error:
////spec
\spec
For new restify resolver, path cannot start with \
.
When I tried to just comment this line https://github.com/mikestead/swagger-routes/blob/master/src/routeRegister.js#L36 then everything else is working correctly and it loads all paths same as before.
Testing this with node v16 and restify v8.6 and cant reproduce this. maybe path.normalise
worked differently in older node version?
When I run it on Windows update of node.js and restify does not seem to help