From cfffb0d8d0c7db2a4dfd7fafb8d9a16290a153f9 Mon Sep 17 00:00:00 2001 From: Zackary Runner Date: Wed, 17 Oct 2018 01:02:48 -0700 Subject: [PATCH 1/2] case insensitive segments during folder tree building --- lib/helpers.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index c61c70f9..e63f2bf2 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -355,7 +355,8 @@ module.exports = { thisPathObject, thisPathCount, len, - i; + i, + segmentKey; //if a particular path has MORE than 1 props, make it a folder - always //how to detemine subfolders? @@ -417,8 +418,9 @@ module.exports = { treeNode = tree; for (i = 0; i < len; i++) { - if (!treeNode.children[thisPath[i]]) { - treeNode.children[thisPath[i]] = { + segmentKey = thisPath[i].toUpperCase(); + if (!treeNode.children[segmentKey]) { + treeNode.children[segmentKey] = { name: thisPath[i], requestCount: 0, children: {}, @@ -427,8 +429,8 @@ module.exports = { }; } - treeNode.children[thisPath[i]].requestCount += thisPathCount; - treeNode = treeNode.children[thisPath[i]]; + treeNode.children[segmentKey].requestCount += thisPathCount; + treeNode = treeNode.children[segmentKey]; } // loop complete. Add the children here From 5948d7f4fdb6044e3af9081f8369a0daf36e23c1 Mon Sep 17 00:00:00 2001 From: Zackary Runner Date: Thu, 18 Oct 2018 12:11:56 -0700 Subject: [PATCH 2/2] add tests --- test/unit/base.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/unit/base.test.js b/test/unit/base.test.js index 32ddb74f..d5851c81 100644 --- a/test/unit/base.test.js +++ b/test/unit/base.test.js @@ -42,6 +42,28 @@ describe('The converter must identify invalid specs: ', function () { //Helpers describe('Helpers', function () { + it('getTreeFromPaths Routes should not be case sensitive', function() { + var json = { + paths:{ + "/Foo/bar":{"get":{}}, + "/FOO/baz":{"get":{}} + } + }, + tree = Helpers.getTreeFromPaths(json); + + var names = []; + for (var child in tree.children) { + if (tree.children.hasOwnProperty(child)) { + names.push(tree.children[child].name); + console.log(child); + } + } + expect(names.length).to.equal(1); + expect(names[0]).to.equal("Foo"); + expect(tree.children["FOO"].children["BAR"].name).equals("bar"); + expect(tree.children["FOO"].children["BAZ"].name).equals("baz"); + }); + it('getBasePath should return the correct basePath', function() { var swagger = { host: 'getpostman.com',