diff --git a/__tests__/oas.test.js b/__tests__/oas.test.js index 0861a30f..87fc5546 100644 --- a/__tests__/oas.test.js +++ b/__tests__/oas.test.js @@ -139,7 +139,7 @@ describe('class.Oas', () => { const method = 'DELETE'; const res = oas.findOperation(uri, method); - expect(res.logOperation).toMatchObject({ + expect(res).toMatchObject({ url: { origin: 'http://petstore.swagger.io/v2', path: '/pet/:petId', @@ -337,7 +337,7 @@ describe('class.operation', () => { const uri = `http://petstore.swagger.io/v2/pet/1`; const method = 'DELETE'; - const { logOperation } = oas.findOperation(uri, method); + const logOperation = oas.findOperation(uri, method); const operation = new Operation(oas, logOperation.url.path, logOperation.url.method, logOperation.operation); expect(operation.getHeaders()).toMatchObject({ @@ -351,7 +351,7 @@ describe('class.operation', () => { const uri = 'http://example.com/multiple-combo-auths'; const method = 'POST'; - const { logOperation } = oas.findOperation(uri, method); + const logOperation = oas.findOperation(uri, method); const operation = new Operation(oas, logOperation.url.path, logOperation.url.method, logOperation.operation); expect(operation.getHeaders()).toMatchObject({ diff --git a/src/oas.js b/src/oas.js index 5270726b..a304a49a 100644 --- a/src/oas.js +++ b/src/oas.js @@ -178,23 +178,20 @@ function filterPathMethods(pathMatches, targetMethod) { .filter(p => p); } -function findTargetPath(pathMatches, index) { +function findTargetPath(pathMatches) { let minCount = Object.keys(pathMatches[0].url.slugs).length; - let logOperation; + let operation; for (let m = 0; m < pathMatches.length; m += 1) { const selection = pathMatches[m]; const paramCount = Object.keys(selection.url.slugs).length; if (paramCount <= minCount) { minCount = paramCount; - logOperation = selection; + operation = selection; } } - return { - logOperation, - index, - }; + return operation; } class Oas { @@ -225,7 +222,7 @@ class Oas { return new Operation(this, path, method, operation); } - findOperation(url, method, index = 0) { + findOperation(url, method) { const { origin } = new URL(url); const originRegExp = new RegExp(origin); const { servers, paths } = this; @@ -240,7 +237,7 @@ class Oas { const includesMethod = filterPathMethods(annotatedPaths, method); if (!includesMethod.length) return undefined; - return findTargetPath(includesMethod, index); + return findTargetPath(includesMethod); } }