@scalar/oas-utils
Advanced tools
Comparing version 0.1.12 to 0.1.13
# @scalar/oas-utils | ||
## 0.1.13 | ||
### Patch Changes | ||
- 5aa656f: feat: [BREAKING CHANGE] use new HTTP proxy (https://github.com/scalar/scalar/pull/1703) | ||
## 0.1.12 | ||
@@ -4,0 +10,0 @@ |
export { createHash } from './createHash'; | ||
export { defaultStateFactory, ssrState } from './ssrState'; | ||
export { fetchSpecFromUrl } from './fetch-spec'; | ||
export { fetchSpecFromUrl } from './fetchSpecFromUrl'; | ||
export { getExampleFromSchema } from './getExampleFromSchema'; | ||
@@ -5,0 +5,0 @@ export { getHarRequest } from './getHarRequest'; |
@@ -89,21 +89,18 @@ import { parse, stringify } from 'yaml'; | ||
function redirectToProxy(proxy, url) { | ||
return `${proxy}?scalar_url=${encodeURI(url)}`; | ||
} | ||
async function fetchSpecFromUrl(url, proxy) { | ||
const response = proxy ? await fetch(proxy, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ | ||
method: "GET", | ||
url | ||
}) | ||
}) : await fetch(url); | ||
const response = await fetch(proxy ? redirectToProxy(proxy, url) : url); | ||
if (response.status !== 200) { | ||
const proxyWarning = proxy ? "" : "Trying to fetch the spec file without a proxy. The CORS headers must be set properly or the request will fail."; | ||
console.error( | ||
`[fetchSpecFromUrl] Failed to fetch the spec at ${url}. ${proxyWarning}` | ||
`[fetchSpecFromUrl] Failed to fetch the specification at ${url} (Status: ${response.status})` | ||
); | ||
if (!proxy) { | ||
console.warn( | ||
`[fetchSpecFromUrl] Tried to fetch the specification (url: ${url}) without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS` | ||
); | ||
} | ||
} | ||
const payload = proxy ? String((await response.json()).data) : await response.text(); | ||
return formatJsonOrYamlString(payload); | ||
return formatJsonOrYamlString(await response.text()); | ||
} | ||
@@ -110,0 +107,0 @@ |
@@ -28,3 +28,3 @@ import { stringify } from 'yaml'; | ||
export declare const transformToJson: (value: string) => string; | ||
/** Validates a JSON string if provided. Otherwise returns the raw Yaml */ | ||
/** Validates a JSON string if provided. Otherwise returns the raw YAML */ | ||
export declare function formatJsonOrYamlString(value: string): string; | ||
@@ -31,0 +31,0 @@ /** Parse JSON or YAML into an object */ |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"engines": { | ||
@@ -22,0 +22,0 @@ "node": ">=18" |
Sorry, the diff of this file is not supported yet
50348
1
1167