diff --git a/packages/oc-docs/src/runner/RequestExecutor.spec.ts b/packages/oc-docs/src/runner/RequestExecutor.spec.ts index 00f214ef..2ba9acf6 100644 --- a/packages/oc-docs/src/runner/RequestExecutor.spec.ts +++ b/packages/oc-docs/src/runner/RequestExecutor.spec.ts @@ -27,6 +27,13 @@ describe('applyApiKeyToUrl', () => { const auth = { type: 'apikey', key: 'api_key', value: 'secret123', placement: 'query' }; expect(applyApiKeyToUrl('api.example.com/data', auth)).toBe('api.example.com/data'); }); + + it('leaves the url untouched when the value is empty', () => { + const auth = { type: 'apikey', key: 'api_key', value: '', placement: 'query' }; + expect(applyApiKeyToUrl('https://api.example.com/data', auth)).toBe( + 'https://api.example.com/data' + ); + }); }); describe('RequestExecutor', () => { diff --git a/packages/oc-docs/src/runner/RequestExecutor.ts b/packages/oc-docs/src/runner/RequestExecutor.ts index 9bcd95a3..e4ca2b0d 100644 --- a/packages/oc-docs/src/runner/RequestExecutor.ts +++ b/packages/oc-docs/src/runner/RequestExecutor.ts @@ -6,7 +6,7 @@ import { classifyRequestError, DEFAULT_TIMEOUT_MS } from './classifyRequestError import stripJsonComments from 'strip-json-comments'; export const applyApiKeyToUrl = (url: string, auth: Record | undefined): string => { - if (auth?.type !== 'apikey' || auth.placement !== 'query' || !auth.key) { + if (auth?.type !== 'apikey' || auth.placement !== 'query' || !auth.key || !auth.value) { return url; }