diff --git a/__tests__/parse-swagger-doc.spec.js b/__tests__/parse-swagger-doc.spec.js index f875512..950dba1 100644 --- a/__tests__/parse-swagger-doc.spec.js +++ b/__tests__/parse-swagger-doc.spec.js @@ -3,7 +3,9 @@ const { parseSwaggerDoc } = require('../src/converter') test('should return empty entries', () => { const swagger = { paths: { - 'x-swagger-router-controller': 'health', + '/emojis': { + 'x-swagger-router-controller': 'health' + } }, } const entries = parseSwaggerDoc(swagger, 'https://example.com') @@ -13,8 +15,8 @@ test('should return empty entries', () => { test('should skip x-swagger-router-controller from paths', () => { const swagger = { paths: { - 'x-swagger-router-controller': 'health', '/emojis': { + 'x-swagger-router-controller': 'health', get: { parameters: [ { diff --git a/src/converter.js b/src/converter.js index 9c4aba3..5764dfd 100644 --- a/src/converter.js +++ b/src/converter.js @@ -409,11 +409,11 @@ const parseSwaggerDoc = (swagger, baseUrl) => { const harList = [] for (const path in swagger.paths) { - if (path.startsWith('x-swagger-router-controller')) { - continue - } - for (const method in swagger.paths[path]) { + if (method && method.toLowerCase().startsWith('x-swagger-router-controller')) { + continue + } + const url = removeTrailingSlash(baseUrl) + '/' + removeLeadingSlash(path) const har = createHar(swagger, baseUrl, path, method)