diff --git a/packages/react-openapi/src/fetchOpenAPIOperation.test.ts b/packages/react-openapi/src/fetchOpenAPIOperation.test.ts index 99f41786fb..75a134042f 100644 --- a/packages/react-openapi/src/fetchOpenAPIOperation.test.ts +++ b/packages/react-openapi/src/fetchOpenAPIOperation.test.ts @@ -149,3 +149,37 @@ it('should parse Swagger 2.0', async () => { }, }); }); + +it('should resolve a ref with whitespace', async () => { + const resolved = await fetchOpenAPIOperation( + { + url: ' https://petstore3.swagger.io/api/v3/openapi.json', + method: 'put', + path: '/pet', + }, + fetcher, + ); + + expect(resolved).toMatchObject({ + servers: [ + { + url: '/api/v3', + }, + ], + operation: { + tags: ['pet'], + summary: 'Update an existing pet', + description: 'Update an existing pet by Id', + requestBody: { + content: { + 'application/json': { + schema: { + type: 'object', + required: ['name', 'photoUrls'], + }, + }, + }, + }, + }, + }); +}); \ No newline at end of file diff --git a/src/lib/images.ts b/src/lib/images.ts index bb71328d32..3d366adc1b 100644 --- a/src/lib/images.ts +++ b/src/lib/images.ts @@ -185,7 +185,7 @@ export async function resizeImage( return response; } - return fetch(input, { + return fetch(parsed, { // @ts-ignore cf: { image: resizeOptions, diff --git a/src/lib/openapi.ts b/src/lib/openapi.ts index cdc6169328..1486e17073 100644 --- a/src/lib/openapi.ts +++ b/src/lib/openapi.ts @@ -55,8 +55,10 @@ export async function fetchOpenAPIBlock( const fetcher: OpenAPIFetcher = { fetch: cache('openapi.fetch', async (url: string, options: CacheFunctionOptions) => { - console.log('HERE fetch', url); - const response = await fetch(url, { + // Wrap the raw string to prevent invalid URLs from being passed to fetch. + // This can happen if the URL has whitespace, which is currently handled differently by Cloudflare's implementation of fetch: + // + const response = await fetch(new URL(url), { ...noCacheFetchOptions, signal: options.signal, });