Skip to content

Commit

Permalink
fix: edge case in findOperation (#147)
Browse files Browse the repository at this point in the history
If the origin is the same but the path cannot be extracted, it would throw a split error in `generatePathMatches()`. This fixes that case.
  • Loading branch information
kanadgupta authored Mar 30, 2020
1 parent 9f4c91d commit 62583ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/tooling/__tests__/oas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ describe('class.Oas', () => {
expect(res).toBeUndefined();
});

it('should return undefined if origin is correct but unable to extract path', () => {
const oas = new Oas(petstore);
const uri = `http://petstore.swagger.io/`;
const method = 'GET';

const res = oas.findOperation(uri, method);
expect(res).toBeUndefined();
});

it('should return undefined if no path matches found', () => {
const oas = new Oas(petstore);
const uri = `http://petstore.swagger.io/v2/search`;
Expand Down
1 change: 1 addition & 0 deletions packages/tooling/src/oas.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class Oas {
if (!targetServer) return undefined;

const [, pathName] = url.split(targetServer.url);
if (pathName === undefined) return undefined;
const annotatedPaths = generatePathMatches(paths, pathName, targetServer.url);
if (!annotatedPaths.length) return undefined;

Expand Down

0 comments on commit 62583ec

Please sign in to comment.