@scalar/oas-utils 0.2.63 → 0.2.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchSpecFromUrl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchSpecFromUrl.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,UAAO,GACd,OAAO,CAAC,MAAM,CAAC,CA8BjB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { redirectToProxy } from './redirectToProxy.js';
|
|
2
2
|
import { formatJsonOrYamlString } from './parse.js';
|
|
3
3
|
|
|
4
4
|
// Doesn’t work
|
|
@@ -6,7 +6,7 @@ const OLD_PROXY_URL = 'https://api.scalar.com/request-proxy';
|
|
|
6
6
|
// Does work
|
|
7
7
|
const NEW_PROXY_URL = 'https://proxy.scalar.com';
|
|
8
8
|
/**
|
|
9
|
-
* Fetches an OpenAPI/Swagger
|
|
9
|
+
* Fetches an OpenAPI/Swagger specification from a given URL.
|
|
10
10
|
*
|
|
11
11
|
* @throws an error if the fetch fails
|
|
12
12
|
*/
|
|
@@ -16,22 +16,21 @@ async function fetchSpecFromUrl(url, proxy, beautify = true) {
|
|
|
16
16
|
// eslint-disable-next-line no-param-reassign
|
|
17
17
|
proxy = NEW_PROXY_URL;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const text = await response.text();
|
|
25
|
-
// If it's JSON, make it pretty
|
|
26
|
-
return beautify ? formatJsonOrYamlString(text) : text;
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error(`[fetchSpecFromUrl] Failed to fetch the OpenAPI document at ${url}`, error);
|
|
19
|
+
// To use a proxy or not to use a proxy
|
|
20
|
+
const response = await fetch(proxy ? redirectToProxy(proxy, url) : url);
|
|
21
|
+
// Looks like the request failed
|
|
22
|
+
if (response.status !== 200) {
|
|
23
|
+
console.error(`[fetchSpecFromUrl] Failed to fetch the specification at ${url} (Status: ${response.status})`);
|
|
30
24
|
if (!proxy) {
|
|
31
|
-
console.warn(`[fetchSpecFromUrl] Tried to fetch the
|
|
25
|
+
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`);
|
|
32
26
|
}
|
|
33
|
-
throw
|
|
27
|
+
throw new Error(`Failed to fetch the specification (Status: ${response.status})`);
|
|
34
28
|
}
|
|
29
|
+
// If it’s JSON, make it pretty
|
|
30
|
+
if (beautify)
|
|
31
|
+
return formatJsonOrYamlString(await response.text());
|
|
32
|
+
else
|
|
33
|
+
return await response.text();
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export { fetchSpecFromUrl };
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.64",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -108,18 +108,18 @@
|
|
|
108
108
|
"zod": "^3.23.8",
|
|
109
109
|
"@scalar/import": "0.0.3",
|
|
110
110
|
"@scalar/object-utils": "1.1.10",
|
|
111
|
+
"@scalar/openapi-types": "0.1.4",
|
|
111
112
|
"@scalar/themes": "0.9.44",
|
|
112
|
-
"@scalar/types": "0.0.17"
|
|
113
|
-
"@scalar/openapi-types": "0.1.4"
|
|
113
|
+
"@scalar/types": "0.0.17"
|
|
114
114
|
},
|
|
115
115
|
"devDependencies": {
|
|
116
116
|
"type-fest": "^4.20.0",
|
|
117
117
|
"vite": "^5.4.9",
|
|
118
118
|
"vitest": "^1.6.0",
|
|
119
119
|
"zod-to-ts": "^1.2.0",
|
|
120
|
-
"@scalar/build-tooling": "0.1.11",
|
|
121
120
|
"@scalar/openapi-parser": "0.8.8",
|
|
122
|
-
"@scalar/openapi-types": "0.1.4"
|
|
121
|
+
"@scalar/openapi-types": "0.1.4",
|
|
122
|
+
"@scalar/build-tooling": "0.1.11"
|
|
123
123
|
},
|
|
124
124
|
"scripts": {
|
|
125
125
|
"build": "scalar-build-rollup",
|