hyperswitch
Advanced tools
Comparing version 0.8.5 to 0.8.6
@@ -11,2 +11,3 @@ 'use strict'; | ||
const swaggerUI = require('./swaggerUI'); | ||
const URI = require('swagger-router').URI; | ||
@@ -181,3 +182,3 @@ | ||
// Look up the route in the tree. | ||
const match = this._priv.router.route(req.uri); | ||
let match = this._priv.router.route(req.uri); | ||
let handler; | ||
@@ -196,10 +197,19 @@ if (match) { | ||
} | ||
} | ||
if (!handler | ||
&& req.method === 'get' | ||
&& req.uri.path[req.uri.path.length - 1] === '') { | ||
// A GET for an URL that ends with /: return a default listing | ||
if (!match.value) { match.value = {}; } | ||
if (!match.value.path) { match.value.path = '_defaultListingHandler'; } | ||
handler = (hyper, req) => this.defaultListingHandler(match, hyper, req); | ||
if (!handler | ||
&& req.method === 'get' | ||
&& req.uri.path[req.uri.path.length - 1] === '') { | ||
// A GET for an URL that ends with /: return a default listing | ||
const metaPath = req.uri.path.slice(0, -1); | ||
metaPath.push({ type: 'meta', name: 'apiRoot' }); | ||
let metaMatch = this._priv.router.route(new URI(metaPath, {}, true)); | ||
if (match || metaMatch) { | ||
if (!metaMatch) { | ||
metaMatch = { params: match.params }; | ||
} | ||
if (!metaMatch.value) { metaMatch.value = {}; } | ||
if (!metaMatch.value.path) { metaMatch.value.path = '_defaultListingHandler'; } | ||
match = metaMatch; | ||
handler = (hyper, req) => this.defaultListingHandler(metaMatch, hyper, req); | ||
} | ||
@@ -206,0 +216,0 @@ } |
@@ -417,3 +417,2 @@ "use strict"; | ||
const branchNode = this._buildPath(rootNode, path.slice(0, path.length - 1), value); | ||
// Check if we can share the subtree for the pathspec. | ||
@@ -484,3 +483,3 @@ let subtree = this._nodes.get(pathSpec); | ||
if (!parentSegment || parentSegment.name === 'api') { | ||
const listingNode = node.getChild(''); | ||
const listingNode = node.getChild({ type: 'meta', name: 'apiRoot' }); | ||
if (listingNode) { | ||
@@ -626,3 +625,3 @@ scope = scope.makeChild({ | ||
node.setChild('', new Node({ | ||
node.setChild({ type: 'meta', name: 'apiRoot' }, new Node({ | ||
specRoot, | ||
@@ -629,0 +628,0 @@ methods: {}, |
{ | ||
"name": "hyperswitch", | ||
"version": "0.8.5", | ||
"version": "0.8.6", | ||
"description": "REST API creation framework", | ||
@@ -32,3 +32,3 @@ "main": "index.js", | ||
"preq": "^0.4.8", | ||
"swagger-router": "^0.5.1", | ||
"swagger-router": "^0.5.5", | ||
"swagger-ui": "git+https://github.com/wikimedia/swagger-ui#master", | ||
@@ -35,0 +35,0 @@ "json-stable-stringify": "git+https://github.com/wikimedia/json-stable-stringify#master", |
@@ -163,3 +163,3 @@ "use strict"; | ||
.then(function() { | ||
var node = router.route('/test/api/'); | ||
var node = router.route(['test', 'api', { type: 'meta', name: 'apiRoot' }]); | ||
assert.deepEqual(!!node, true); | ||
@@ -181,3 +181,3 @@ assert.deepEqual(!!node.value, true); | ||
.then(function() { | ||
var node = router.route('/'); | ||
var node = router.route([{ type: 'meta', name: 'apiRoot' }]); | ||
assert.deepEqual(!!node, true); | ||
@@ -369,2 +369,2 @@ assert.deepEqual(!!node.value, true); | ||
}); | ||
}); | ||
}); |
180057
4155
Updatedswagger-router@^0.5.5