From 704ef36d4f42901b876d8db97b20a96bdab20bbf Mon Sep 17 00:00:00 2001 From: Jorge Date: Tue, 18 May 2021 09:56:31 +0200 Subject: [PATCH] fix: support empty auth options --- lib/index.js | 11 +++++++---- test/index.spec.js | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 6c71012..78ea6ba 100644 --- a/lib/index.js +++ b/lib/index.js @@ -253,10 +253,12 @@ function parseOptsAuth (optAuth) { security.push({ [secName]: [] }) } } - return { - components: { securitySchemes }, - security - } + return Object.keys(securitySchemes).length === 0 + ? {} + : { + components: { securitySchemes }, + security + } } /* From the path array compose the real path for OpenApi specs */ @@ -291,6 +293,7 @@ function scrapeURL (url) { function parseServers (domains, serversOpts) { let servers if (serversOpts != null) { + // This map is just to filter not supported fields while no validations are implemented servers = serversOpts.map(({ url, description }) => ({ url, description })) } else { servers = Array.from(domains).map(domain => ({ url: domain })) diff --git a/test/index.spec.js b/test/index.spec.js index 3ef6e89..7fa66e2 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -221,6 +221,14 @@ describe('Library specs', function () { equal(result, EXPECTED_BASIC) }) + it('should not fail if auth is empty object', async function () { + const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, + { + auth: {} + }) + equal(result, EXPECTED_BASIC) + }) + it('should use depth configuration for parse paths', async function () { const result = await postmanToOpenApi(COLLECTION_DEPTH_PATH_PARAMS, OUTPUT_PATH, { pathDepth: 1 }) equal(result, EXPECTED_DEPTH_PATH_PARAMS)