Skip to content

Commit

Permalink
fix: Bug Fix - Query Params (#105)
Browse files Browse the repository at this point in the history
* Bug Fix - Query Params:
Query params were incorrectly being used to generate path match regex. Query strings are now being properly pruned for matching purposes

* Added test case covering query params
  • Loading branch information
gratcliff authored Jan 29, 2020
1 parent d78a628 commit 5c5963f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion __tests__/oas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ describe('class.Oas', () => {
},
});
});

it('should return object if query string is included', () => {
const oas = new Oas(petstore);
const uri = `http://petstore.swagger.io/v2/pet/findByStatus?test=2`;
const method = 'GET';

const res = oas.findOperation(uri, method);
expect(res).toMatchObject({
url: {
origin: 'http://petstore.swagger.io/v2',
path: '/pet/findByStatus',
slugs: {},
method: 'GET',
},
});
});
});
});

Expand Down Expand Up @@ -386,7 +402,7 @@ describe('class.operation', () => {

const logOperation = oas.findOperation(uri, method);
const operation = new Operation(oas, logOperation.url.path, logOperation.url.method, logOperation.operation);
console.log(operation.getHeaders());

expect(operation.getHeaders()).toMatchObject({
request: ['Cookie', 'Authorization'],
response: [],
Expand Down
3 changes: 2 additions & 1 deletion src/oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ function normalizePath(path) {
}

function generatePathMatches(paths, pathName, origin) {
const prunedPathName = pathName.split('?')[0];
return Object.keys(paths)
.map(path => {
const cleanedPath = normalizePath(path);
const matchStatement = match(cleanedPath, { decode: decodeURIComponent });
const matchResult = matchStatement(pathName);
const matchResult = matchStatement(prunedPathName);
const slugs = {};

if (matchResult && Object.keys(matchResult.params).length) {
Expand Down

0 comments on commit 5c5963f

Please sign in to comment.