Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
emmerich committed Apr 4, 2024
1 parent b5b07fd commit 24bf472
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
34 changes: 34 additions & 0 deletions packages/react-openapi/src/fetchOpenAPIOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
},
},
},
},
});
});
2 changes: 1 addition & 1 deletion src/lib/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export async function resizeImage(
return response;
}

return fetch(input, {
return fetch(parsed, {
// @ts-ignore
cf: {
image: resizeOptions,
Expand Down
6 changes: 4 additions & 2 deletions src/lib/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit 24bf472

Please sign in to comment.