From 5a5469cd17247682943cdbda44f3611bbfca7e7a Mon Sep 17 00:00:00 2001 From: Gabriel Ratcliff Date: Wed, 22 Jan 2020 10:41:24 -0800 Subject: [PATCH] Minor improvements suggested by @dok in PR comments: - More robust regex for path matching - findOperation more agnostic --- src/oas.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/oas.js b/src/oas.js index 47926764..ba096d50 100644 --- a/src/oas.js +++ b/src/oas.js @@ -103,16 +103,7 @@ function normalizedUrl(oas) { } function normalizePath(path) { - const curlBacketMatch = /{(.*?)}/; - - return path - .split('/') - .map(p => { - const pathMatch = curlBacketMatch.exec(p); - if (pathMatch) return `:${pathMatch[1]}`; - return p; - }) - .join('/'); + return path.replace(/{(.*?)}/g, ':$1'); } function generatePathMatches(paths, pathName, origin) { @@ -204,8 +195,7 @@ class Oas { return new Operation(this, path, method, operation); } - findOperation(logInput) { - const { url, method } = logInput.request.log.entries[0].request; + findOperation(url, method) { const { origin, pathname } = new URL(url); const { servers, paths } = this;