From 02eb060020de885549e1ebc7f1de4cdea6b07196 Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Thu, 17 Oct 2024 12:53:24 -0400 Subject: [PATCH] feat: replace proxyUrl boolean with string --- packages/oas-to-har/src/index.ts | 15 ++++++--------- packages/oas-to-har/src/lib/types.ts | 11 +++++------ packages/oas-to-har/test/index.test.ts | 13 ++++--------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/oas-to-har/src/index.ts b/packages/oas-to-har/src/index.ts index ca039f10..78e4ad97 100644 --- a/packages/oas-to-har/src/index.ts +++ b/packages/oas-to-har/src/index.ts @@ -223,16 +223,13 @@ export default function oasToHar( values: DataForHAR = {}, auth: AuthForHAR = {}, opts: oasToHarOptions = { - // If true, the operation URL will be rewritten and prefixed with - // a proxy - proxyUrl: false, + // the URL of a proxy to use. Requests will be preefixed with its value; + // for example if you use "https://try.readme.io", a request to + // "https://example.com/some/api" will be sent to + // "https://try.readme.io/https://example.com/some/api" + proxyUrl: '', }, ) { - if (opts.proxyUrl && !opts.proxyAddress) { - // eslint-disable-next-line no-param-reassign - opts.proxyAddress = 'https://try.readme.io'; - } - let operation: Operation; if (!operationSchema || typeof operationSchema.getParameters !== 'function') { /** @@ -292,7 +289,7 @@ export default function oasToHar( if (opts.proxyUrl) { if (oas.getExtension(PROXY_ENABLED, operation)) { - har.url = `${opts.proxyAddress}/${har.url}`; + har.url = `${opts.proxyUrl}/${har.url}`; } } diff --git a/packages/oas-to-har/src/lib/types.ts b/packages/oas-to-har/src/lib/types.ts index 4a325eac..a7a87108 100644 --- a/packages/oas-to-har/src/lib/types.ts +++ b/packages/oas-to-har/src/lib/types.ts @@ -3,10 +3,9 @@ export type AuthForHAR = Record { }); }); - it('should not be prefixed with without option', () => { + it('should not be prefixed without proxyUrl', () => { const har = oasToHar(proxyOas, proxyOas.operation('/path', 'get')); expect(har.log.entries[0].request.url).toBe('https://example.com/path'); }); - it('should be prefixed with try.readme.io with option', () => { - const har = oasToHar(proxyOas, proxyOas.operation('/path', 'get'), {}, {}, { proxyUrl: true }); - expect(har.log.entries[0].request.url).toBe('https://try.readme.io/https://example.com/path'); - }); - - it('should be prefixed with beta.try.readme.io with proxyAddress option', () => { + it('should be prefixed with proxyUrl', () => { const har = oasToHar( proxyOas, proxyOas.operation('/path', 'get'), {}, {}, - { proxyUrl: true, proxyAddress: 'https://beta.try.readme.io' }, + { proxyUrl: 'https://try.readme.io' }, ); - expect(har.log.entries[0].request.url).toBe('https://beta.try.readme.io/https://example.com/path'); + expect(har.log.entries[0].request.url).toBe('https://try.readme.io/https://example.com/path'); }); }); });