Swagger 2 router
Features
O(path element)
lookup complexity, monomorphic design with simple fast path.- Support for prefix-based 'mounting' of swagger specs. Example: Mount the
same spec fragments at
/en.wikipedia.org/v1/
and
/de.wikipedia.org/v1/
. - Support for capture of fixed path segments. Example:
/{domain:en.wikipedia.org}/v1/
. This feature is especially useful in
prefixes, as it enables the consistent construction of sensible params. - Support for static (purely spec-based) listings. Matching requests ending on
a slash are passed an array of matching child paths in the spec in the
_ls
parameter.
Installation
npm install swagger-router
Usage
var Router = require('swagger-router');
var router = new Router();
var swaggerSpec = {
paths: {
'/': {
get: {
hello: 'A listing'
}
},
'/some/{name}': {
get: {
hello: 'world'
}
}
}
};
router.addSpec(swaggerSpec);
console.log(router.lookup('/some/title'));
router.lookup(['some','path']);
router.lookup(['']);