@scalar/oas-utils 0.1.12 → 0.1.14
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 +13 -0
- package/dist/fetchSpecFromUrl.d.ts +3 -0
- package/dist/fetchSpecFromUrl.d.ts.map +1 -0
- package/dist/getExampleFromSchema.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -14
- package/dist/normalizeMimeType.d.ts +7 -1
- package/dist/normalizeMimeType.d.ts.map +1 -1
- package/dist/normalizeMimeTypeObject.d.ts.map +1 -1
- package/dist/parse.d.ts +1 -1
- package/package.json +1 -1
- package/dist/fetch-spec.d.ts +0 -3
- package/dist/fetch-spec.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.1.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7205137: fix: response body does not show a preview when the content-type is undefined
|
|
8
|
+
- d369ac4: feat: union types in getExampleFromSchema
|
|
9
|
+
|
|
10
|
+
## 0.1.13
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 5aa656f: feat: [BREAKING CHANGE] use new HTTP proxy (https://github.com/scalar/scalar/pull/1703)
|
|
15
|
+
|
|
3
16
|
## 0.1.12
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../src/fetchSpecFromUrl.ts"],"names":[],"mappings":"AAYA,iEAAiE;AACjE,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExampleFromSchema.d.ts","sourceRoot":"","sources":["../src/getExampleFromSchema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,OAAO,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;QAGI;IACJ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,UACM,MAAM,KACZ,
|
|
1
|
+
{"version":3,"file":"getExampleFromSchema.d.ts","sourceRoot":"","sources":["../src/getExampleFromSchema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,OAAO,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;QAGI;IACJ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,UACM,MAAM,KACZ,GA2PF,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createHash } from './createHash';
|
|
2
2
|
export { defaultStateFactory, ssrState } from './ssrState';
|
|
3
|
-
export { fetchSpecFromUrl } from './
|
|
3
|
+
export { fetchSpecFromUrl } from './fetchSpecFromUrl';
|
|
4
4
|
export { getExampleFromSchema } from './getExampleFromSchema';
|
|
5
5
|
export { getHarRequest } from './getHarRequest';
|
|
6
6
|
export { getParametersFromOperation } from './getParametersFromOperation';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,qBAAqB,CAAA;AACnC,cAAc,SAAS,CAAA;AACvB,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,IAAI,EACJ,eAAe,EACf,eAAe,EACf,IAAI,GACL,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -86,25 +86,27 @@ const parseJsonOrYaml = (value) => {
|
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
const OLD_PROXY_URL = "https://api.scalar.com/request-proxy";
|
|
90
|
+
const NEW_PROXY_URL = "https://proxy.scalar.com";
|
|
91
|
+
function redirectToProxy(proxy, url) {
|
|
92
|
+
return `${proxy}?scalar_url=${encodeURI(url)}`;
|
|
93
|
+
}
|
|
89
94
|
async function fetchSpecFromUrl(url, proxy) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
body: JSON.stringify({
|
|
96
|
-
method: "GET",
|
|
97
|
-
url
|
|
98
|
-
})
|
|
99
|
-
}) : await fetch(url);
|
|
95
|
+
if (proxy === OLD_PROXY_URL) {
|
|
96
|
+
proxy = NEW_PROXY_URL;
|
|
97
|
+
}
|
|
98
|
+
const response = await fetch(proxy ? redirectToProxy(proxy, url) : url);
|
|
100
99
|
if (response.status !== 200) {
|
|
101
|
-
const proxyWarning = proxy ? "" : "Trying to fetch the spec file without a proxy. The CORS headers must be set properly or the request will fail.";
|
|
102
100
|
console.error(
|
|
103
|
-
`[fetchSpecFromUrl] Failed to fetch the
|
|
101
|
+
`[fetchSpecFromUrl] Failed to fetch the specification at ${url} (Status: ${response.status})`
|
|
104
102
|
);
|
|
103
|
+
if (!proxy) {
|
|
104
|
+
console.warn(
|
|
105
|
+
`[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`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
|
-
|
|
107
|
-
return formatJsonOrYamlString(payload);
|
|
109
|
+
return formatJsonOrYamlString(await response.text());
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
const getExampleFromSchema = (schema, options, level = 0) => {
|
|
@@ -263,6 +265,15 @@ const getExampleFromSchema = (schema, options, level = 0) => {
|
|
|
263
265
|
});
|
|
264
266
|
return example;
|
|
265
267
|
}
|
|
268
|
+
if (Array.isArray(schema.type)) {
|
|
269
|
+
if (schema.type.includes("null")) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
const exampleValue = exampleValues[schema.type[0]];
|
|
273
|
+
if (exampleValue !== void 0) {
|
|
274
|
+
return exampleValue;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
266
277
|
console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`);
|
|
267
278
|
return null;
|
|
268
279
|
};
|
|
@@ -377,6 +388,9 @@ function json2xml(data, tab) {
|
|
|
377
388
|
}
|
|
378
389
|
|
|
379
390
|
function normalizeMimeType(contentType) {
|
|
391
|
+
if (typeof contentType !== "string") {
|
|
392
|
+
return void 0;
|
|
393
|
+
}
|
|
380
394
|
return contentType.replace(/;.*$/, "").replace(/\/.+\+/, "/").trim();
|
|
381
395
|
}
|
|
382
396
|
|
|
@@ -389,6 +403,9 @@ function normalizeMimeTypeObject(content) {
|
|
|
389
403
|
};
|
|
390
404
|
Object.keys(newContent).forEach((key) => {
|
|
391
405
|
const newKey = normalizeMimeType(key);
|
|
406
|
+
if (newKey === void 0) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
392
409
|
newContent[newKey] = newContent[key];
|
|
393
410
|
if (key !== newKey) {
|
|
394
411
|
delete newContent[key];
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { ContentType } from './types';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes a MIME type to a standard format.
|
|
4
|
+
*
|
|
5
|
+
* Input: application/problem+json; charset=utf-8
|
|
6
|
+
* Output: application/json
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeMimeType(contentType?: string): ContentType | undefined;
|
|
3
9
|
//# sourceMappingURL=normalizeMimeType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeMimeType.d.ts","sourceRoot":"","sources":["../src/normalizeMimeType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"normalizeMimeType.d.ts","sourceRoot":"","sources":["../src/normalizeMimeType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,2BAcrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeMimeTypeObject.d.ts","sourceRoot":"","sources":["../src/normalizeMimeTypeObject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC;;;;;;;;
|
|
1
|
+
{"version":3,"file":"normalizeMimeTypeObject.d.ts","sourceRoot":"","sources":["../src/normalizeMimeTypeObject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC;;;;;;;;cA8BzE"}
|
package/dist/parse.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare const isJsonString: (value?: any) => boolean;
|
|
|
25
25
|
* This helper is used to transform the content of the swagger file to JSON, even it was YAML.
|
|
26
26
|
*/
|
|
27
27
|
export declare const transformToJson: (value: string) => string;
|
|
28
|
-
/** Validates a JSON string if provided. Otherwise returns the raw
|
|
28
|
+
/** Validates a JSON string if provided. Otherwise returns the raw YAML */
|
|
29
29
|
export declare function formatJsonOrYamlString(value: string): string;
|
|
30
30
|
/** Parse JSON or YAML into an object */
|
|
31
31
|
export declare const parseJsonOrYaml: (value: string | AnyObject) => AnyObject;
|
package/package.json
CHANGED
package/dist/fetch-spec.d.ts
DELETED
package/dist/fetch-spec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-spec.d.ts","sourceRoot":"","sources":["../src/fetch-spec.ts"],"names":[],"mappings":"AAEA,iDAAiD;AACjD,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CA8BjB"}
|