@scalar/oas-utils 0.2.119 → 0.2.121
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 +20 -0
- package/dist/diff/diff.d.ts.map +1 -1
- package/dist/diff/diff.js +2 -1
- package/dist/helpers/createHash.d.ts.map +1 -1
- package/dist/helpers/createHash.js +2 -1
- package/dist/helpers/ensure-protocol.d.ts.map +1 -1
- package/dist/helpers/ensure-protocol.js +2 -1
- package/dist/helpers/fetchSpecFromUrl.d.ts.map +1 -1
- package/dist/helpers/fetchSpecFromUrl.js +3 -3
- package/dist/helpers/iterateTitle.d.ts.map +1 -1
- package/dist/helpers/iterateTitle.js +2 -1
- package/dist/helpers/json2xml.d.ts.map +1 -1
- package/dist/helpers/json2xml.js +13 -8
- package/dist/helpers/merge-urls.d.ts.map +1 -1
- package/dist/helpers/merge-urls.js +5 -3
- package/dist/helpers/parse.d.ts.map +1 -1
- package/dist/helpers/parse.js +12 -6
- package/dist/helpers/prettyPrintJson.js +1 -1
- package/dist/helpers/redirectToProxy.d.ts.map +1 -1
- package/dist/helpers/redirectToProxy.js +6 -3
- package/dist/helpers/replaceVariables.d.ts.map +1 -1
- package/dist/helpers/replaceVariables.js +1 -3
- package/dist/helpers/schema-model.js +2 -1
- package/dist/migrations/local-storage.d.ts.map +1 -1
- package/dist/migrations/local-storage.js +6 -3
- package/dist/migrations/migrator.d.ts.map +1 -1
- package/dist/migrations/migrator.js +10 -5
- package/dist/migrations/semver.d.ts.map +1 -1
- package/dist/migrations/semver.js +9 -5
- package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.1.0/migration.js +21 -11
- package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.2.0/migration.js +4 -2
- package/dist/spec-getters/getExampleFromSchema.d.ts.map +1 -1
- package/dist/spec-getters/getExampleFromSchema.js +6 -8
- package/dist/spec-getters/getParametersFromOperation.d.ts.map +1 -1
- package/dist/spec-getters/getParametersFromOperation.js +4 -2
- package/dist/transforms/import-spec.d.ts +4 -2
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +39 -19
- package/dist/transforms/index.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.2.121
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0f13162: chore: enable more Biome flags, apply linter fixes
|
|
8
|
+
- 0212daa: fix(api-client): client not being set without scope
|
|
9
|
+
- Updated dependencies [7a8965c]
|
|
10
|
+
- Updated dependencies [49dffff]
|
|
11
|
+
- @scalar/types@0.1.2
|
|
12
|
+
- @scalar/themes@0.9.80
|
|
13
|
+
|
|
14
|
+
## 0.2.120
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- cd75eeb: fix: update collection in multi doc
|
|
19
|
+
- Updated dependencies [39c0f47]
|
|
20
|
+
- @scalar/types@0.1.1
|
|
21
|
+
- @scalar/themes@0.9.79
|
|
22
|
+
|
|
3
23
|
## 0.2.119
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/diff/diff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff/diff.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,KAAK;;;;CAID,CAAA;AAEV,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,OAAO,KAAK,CAAC,CAAA;AAE/D;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff/diff.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,KAAK;;;;CAID,CAAA;AAEV,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,OAAO,KAAK,CAAC,CAAA;AAE/D;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,UAsC5C"}
|
package/dist/diff/diff.js
CHANGED
|
@@ -19,11 +19,12 @@ function diffSpec(a, b) {
|
|
|
19
19
|
.slice(0, 3)
|
|
20
20
|
.map((p) => String(p).replaceAll('/', '~1'))
|
|
21
21
|
.join('/');
|
|
22
|
-
if (!requestChanges[key])
|
|
22
|
+
if (!requestChanges[key]) {
|
|
23
23
|
requestChanges[key] = {
|
|
24
24
|
type: types[d.type],
|
|
25
25
|
mutations: [],
|
|
26
26
|
};
|
|
27
|
+
}
|
|
27
28
|
if (d.type === 'CHANGE') {
|
|
28
29
|
requestChanges[key].mutations.push({
|
|
29
30
|
...d,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHash.d.ts","sourceRoot":"","sources":["../../src/helpers/createHash.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,UAAU,WAAY,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"createHash.d.ts","sourceRoot":"","sources":["../../src/helpers/createHash.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,UAAU,WAAY,MAAM,KAAG,MAe3C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-protocol.d.ts","sourceRoot":"","sources":["../../src/helpers/ensure-protocol.ts"],"names":[],"mappings":"AAEA,uCAAuC;AACvC,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ensure-protocol.d.ts","sourceRoot":"","sources":["../../src/helpers/ensure-protocol.ts"],"names":[],"mappings":"AAEA,uCAAuC;AACvC,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOlD"}
|
|
@@ -2,8 +2,9 @@ import { REGEX } from './regexHelpers.js';
|
|
|
2
2
|
|
|
3
3
|
/** Ensure URL has a protocol prefix */
|
|
4
4
|
function ensureProtocol(url) {
|
|
5
|
-
if (REGEX.PROTOCOL.test(url))
|
|
5
|
+
if (REGEX.PROTOCOL.test(url)) {
|
|
6
6
|
return url;
|
|
7
|
+
}
|
|
7
8
|
// Default to http if no protocol is specified
|
|
8
9
|
return `http://${url.replace(/^\//, '')}`;
|
|
9
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchSpecFromUrl.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"fetchSpecFromUrl.d.ts","sourceRoot":"","sources":["../../src/helpers/fetchSpecFromUrl.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BpG"}
|
|
@@ -27,10 +27,10 @@ async function fetchSpecFromUrl(url, proxy, beautify = true) {
|
|
|
27
27
|
throw new Error(`Failed to fetch the specification (Status: ${response.status})`);
|
|
28
28
|
}
|
|
29
29
|
// If it’s JSON, make it pretty
|
|
30
|
-
if (beautify)
|
|
30
|
+
if (beautify) {
|
|
31
31
|
return formatJsonOrYamlString(await response.text());
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
}
|
|
33
|
+
return await response.text();
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export { fetchSpecFromUrl };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterateTitle.d.ts","sourceRoot":"","sources":["../../src/helpers/iterateTitle.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,mBAAmB,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,yBAAqB,
|
|
1
|
+
{"version":3,"file":"iterateTitle.d.ts","sourceRoot":"","sources":["../../src/helpers/iterateTitle.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,mBAAmB,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,yBAAqB,MAa3G,CAAA"}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const iterateTitle = (title, checkDuplicates, separator = ' #') => {
|
|
5
5
|
// If the title is not a duplicate return
|
|
6
|
-
if (!checkDuplicates(title))
|
|
6
|
+
if (!checkDuplicates(title)) {
|
|
7
7
|
return title;
|
|
8
|
+
}
|
|
8
9
|
const split = title.split(separator);
|
|
9
10
|
const newTitle = split.length > 1
|
|
10
11
|
? `${split.slice(0, -1).join()}${separator}${Number(split.at(-1)) + 1}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json2xml.d.ts","sourceRoot":"","sources":["../../src/helpers/json2xml.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"json2xml.d.ts","sourceRoot":"","sources":["../../src/helpers/json2xml.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,UAgD/D"}
|
package/dist/helpers/json2xml.js
CHANGED
|
@@ -4,31 +4,36 @@
|
|
|
4
4
|
function json2xml(data, tab) {
|
|
5
5
|
const toXml = (value, key, indentation) => {
|
|
6
6
|
let xml = '';
|
|
7
|
-
if (value
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
8
|
for (let i = 0, n = value.length; i < n; i++) {
|
|
9
9
|
xml += indentation + toXml(value[i], key, indentation + '\t') + '\n';
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
else if (typeof value
|
|
12
|
+
else if (typeof value === 'object') {
|
|
13
13
|
let hasChild = false;
|
|
14
14
|
xml += indentation + '<' + key;
|
|
15
15
|
for (const m in value) {
|
|
16
|
-
if (m.charAt(0)
|
|
16
|
+
if (m.charAt(0) === '@') {
|
|
17
17
|
xml += ' ' + m.substr(1) + '="' + value[m].toString() + '"';
|
|
18
|
-
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
19
20
|
hasChild = true;
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
xml += hasChild ? '>' : '/>';
|
|
22
24
|
if (hasChild) {
|
|
23
25
|
for (const m in value) {
|
|
24
|
-
if (m
|
|
26
|
+
if (m === '#text') {
|
|
25
27
|
xml += value[m];
|
|
26
|
-
|
|
28
|
+
}
|
|
29
|
+
else if (m === '#cdata') {
|
|
27
30
|
xml += '<![CDATA[' + value[m] + ']]>';
|
|
28
|
-
|
|
31
|
+
}
|
|
32
|
+
else if (m.charAt(0) !== '@') {
|
|
29
33
|
xml += toXml(value[m], m, indentation + '\t');
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
|
-
xml += (xml.charAt(xml.length - 1)
|
|
36
|
+
xml += (xml.charAt(xml.length - 1) === '\n' ? indentation : '') + '</' + key + '>';
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-urls.d.ts","sourceRoot":"","sources":["../../src/helpers/merge-urls.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,cAAe,eAAe,EAAE,KAAG,eA6BhE,CAAA;AAED,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,QAAS,MAAM,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"merge-urls.d.ts","sourceRoot":"","sources":["../../src/helpers/merge-urls.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,cAAe,eAAe,EAAE,KAAG,eA6BhE,CAAA;AAED,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,QAAS,MAAM,QAAQ,MAAM,WAU1D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,QACf,MAAM,QACL,MAAM,cACD,eAAe,0CAmC3B,CAAA"}
|
|
@@ -34,10 +34,12 @@ const mergeSearchParams = (...params) => {
|
|
|
34
34
|
};
|
|
35
35
|
/** Combines a base URL and a path ensuring there's only one slash between them */
|
|
36
36
|
const combineUrlAndPath = (url, path) => {
|
|
37
|
-
if (!path || url === path)
|
|
37
|
+
if (!path || url === path) {
|
|
38
38
|
return url.trim();
|
|
39
|
-
|
|
39
|
+
}
|
|
40
|
+
if (!url) {
|
|
40
41
|
return path.trim();
|
|
42
|
+
}
|
|
41
43
|
return `${url.trim()}/${path.trim()}`.replace(REGEX.MULTIPLE_SLASHES, '/');
|
|
42
44
|
};
|
|
43
45
|
/**
|
|
@@ -70,7 +72,7 @@ disableOriginPrefix = false) => {
|
|
|
70
72
|
const search = mergedSearchParams.toString();
|
|
71
73
|
return search ? `${mergedUrl}?${search}` : mergedUrl;
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
if (path) {
|
|
74
76
|
return combineUrlAndPath(url, path);
|
|
75
77
|
}
|
|
76
78
|
return '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/helpers/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAS,SAAS,EAAE,MAAM,MAAM,CAAA;AAEvC,KAAK,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;AAE9E,4CAA4C;AAC5C,eAAO,MAAM,IAAI;IACf,2DAA2D;iBAC9C,MAAM,
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/helpers/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAS,SAAS,EAAE,MAAM,MAAM,CAAA;AAEvC,KAAK,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;AAE9E,4CAA4C;AAC5C,eAAO,MAAM,IAAI;IACf,2DAA2D;iBAC9C,MAAM,KAKI,aAAa;IAEpC,6CAA6C;cACnC,CAAC,SAAS,iBAAiB,OAAO,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,aAAa,GAAG,CAAC;;CAQxG,CAAA;AAED,4CAA4C;AAC5C,eAAO,MAAM,IAAI;IACf,2DAA2D;iBAC9C,MAAM,KAAG,aAAa;IAOnC,6CAA6C;cACnC,CAAC,SAAS,iBAAiB,OAAO,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,GAAG,aAAa,GAAG,CAAC;qBAOtF,MAAM;CACxB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,WAAY,GAAG,YAMvC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,WAG5C,CAAA;AAED,0EAA0E;AAC1E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,UAcnD;AAED,wCAAwC;AACxC,eAAO,MAAM,eAAe,UAAW,MAAM,GAAG,aAAa,KAAG,aAkB/D,CAAA"}
|
package/dist/helpers/parse.js
CHANGED
|
@@ -5,8 +5,9 @@ const yaml = {
|
|
|
5
5
|
/** Parse and throw if the return value is not an object */
|
|
6
6
|
parse: (val) => {
|
|
7
7
|
const yamlObject = parse(val);
|
|
8
|
-
if (typeof yamlObject !== 'object')
|
|
8
|
+
if (typeof yamlObject !== 'object') {
|
|
9
9
|
throw Error('Invalid YAML object');
|
|
10
|
+
}
|
|
10
11
|
return yamlObject;
|
|
11
12
|
},
|
|
12
13
|
/** Parse and return a fallback on failure */
|
|
@@ -25,8 +26,9 @@ const json = {
|
|
|
25
26
|
/** Parse and throw if the return value is not an object */
|
|
26
27
|
parse: (val) => {
|
|
27
28
|
const jsonObject = JSON.parse(val);
|
|
28
|
-
if (typeof jsonObject !== 'object')
|
|
29
|
+
if (typeof jsonObject !== 'object') {
|
|
29
30
|
throw Error('Invalid JSON object');
|
|
31
|
+
}
|
|
30
32
|
return jsonObject;
|
|
31
33
|
},
|
|
32
34
|
/** Parse and return a fallback on failure */
|
|
@@ -44,8 +46,9 @@ const json = {
|
|
|
44
46
|
* Check if value is a valid JSON string
|
|
45
47
|
*/
|
|
46
48
|
const isJsonString = (value) => {
|
|
47
|
-
if (typeof value !== 'string')
|
|
49
|
+
if (typeof value !== 'string') {
|
|
48
50
|
return false;
|
|
51
|
+
}
|
|
49
52
|
return !!json.parseSafe(value, false);
|
|
50
53
|
};
|
|
51
54
|
/**
|
|
@@ -59,8 +62,9 @@ const transformToJson = (value) => {
|
|
|
59
62
|
function formatJsonOrYamlString(value) {
|
|
60
63
|
// If we don't start with a bracket assume yaml
|
|
61
64
|
const trimmed = value.trim();
|
|
62
|
-
if (trimmed[0] !== '{' && trimmed[0] !== '[')
|
|
65
|
+
if (trimmed[0] !== '{' && trimmed[0] !== '[') {
|
|
63
66
|
return value;
|
|
67
|
+
}
|
|
64
68
|
try {
|
|
65
69
|
// JSON
|
|
66
70
|
return JSON.stringify(JSON.parse(value), null, 2);
|
|
@@ -72,11 +76,13 @@ function formatJsonOrYamlString(value) {
|
|
|
72
76
|
}
|
|
73
77
|
/** Parse JSON or YAML into an object */
|
|
74
78
|
const parseJsonOrYaml = (value) => {
|
|
75
|
-
if (typeof value !== 'string')
|
|
79
|
+
if (typeof value !== 'string') {
|
|
76
80
|
return value;
|
|
81
|
+
}
|
|
77
82
|
const jsonObject = json.parseSafe(value, null);
|
|
78
|
-
if (jsonObject)
|
|
83
|
+
if (jsonObject) {
|
|
79
84
|
return jsonObject;
|
|
85
|
+
}
|
|
80
86
|
// Value is probably supposed to be JSON. Throw
|
|
81
87
|
if (value.length > 0 && ['{', '['].includes(value[0])) {
|
|
82
88
|
throw Error('Invalid JSON or YAML');
|
|
@@ -28,7 +28,7 @@ const prettyPrintJson = (value) => {
|
|
|
28
28
|
*/
|
|
29
29
|
function replaceCircularDependencies(content) {
|
|
30
30
|
const cache = new Set();
|
|
31
|
-
return JSON.stringify(content, (
|
|
31
|
+
return JSON.stringify(content, (_key, value) => {
|
|
32
32
|
if (typeof value === 'object' && value !== null) {
|
|
33
33
|
if (cache.has(value)) {
|
|
34
34
|
return '[Circular]';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToProxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirectToProxy.ts"],"names":[],"mappings":"AAIA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,wEAAwE;AACxE,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"redirectToProxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirectToProxy.ts"],"names":[],"mappings":"AAIA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,wEAAwE;AACxE,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAiBpE"}
|
|
@@ -30,14 +30,17 @@ const isRelativePath = (url) => {
|
|
|
30
30
|
/** Returns false for requests to localhost, relative URLs, if no proxy is defined … */
|
|
31
31
|
function shouldUseProxy(proxy, url) {
|
|
32
32
|
// No proxy or url
|
|
33
|
-
if (!proxy || !url)
|
|
33
|
+
if (!proxy || !url) {
|
|
34
34
|
return false;
|
|
35
|
+
}
|
|
35
36
|
// Relative URLs
|
|
36
|
-
if (isRelativePath(url))
|
|
37
|
+
if (isRelativePath(url)) {
|
|
37
38
|
return false;
|
|
39
|
+
}
|
|
38
40
|
// Requests to localhost
|
|
39
|
-
if (isLocalUrl(url))
|
|
41
|
+
if (isLocalUrl(url)) {
|
|
40
42
|
return false;
|
|
43
|
+
}
|
|
41
44
|
return true;
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replaceVariables.d.ts","sourceRoot":"","sources":["../../src/helpers/replaceVariables.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"replaceVariables.d.ts","sourceRoot":"","sources":["../../src/helpers/replaceVariables.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,UAenF"}
|
|
@@ -9,9 +9,7 @@ function replaceVariables(value, variablesOrCallback) {
|
|
|
9
9
|
if (typeof variablesOrCallback === 'function') {
|
|
10
10
|
return variablesOrCallback(match);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
return variablesOrCallback[match]?.toString() || `{${match}}`;
|
|
14
|
-
}
|
|
12
|
+
return variablesOrCallback[match]?.toString() || `{${match}}`;
|
|
15
13
|
};
|
|
16
14
|
// Loop through all matches and replace the match with the variable value
|
|
17
15
|
return value.replace(doubleCurlyBrackets, callback).replace(singleCurlyBrackets, callback);
|
|
@@ -7,8 +7,9 @@ function schemaModel(data, schema, throwError = true, errorLocation) {
|
|
|
7
7
|
console.log('Received: ', data);
|
|
8
8
|
console.groupEnd();
|
|
9
9
|
}
|
|
10
|
-
if (throwError && !result.success)
|
|
10
|
+
if (throwError && !result.success) {
|
|
11
11
|
throw new Error('Zod validation failure');
|
|
12
|
+
}
|
|
12
13
|
return result.data;
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/migrations/local-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKxC;;GAEG;AACH,eAAO,MAAM,iBAAiB,UAAW,CAAC,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAKvG,CAAA;AAED,oDAAoD;AACpD,eAAO,MAAM,sBAAsB,QAAO,
|
|
1
|
+
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/migrations/local-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKxC;;GAEG;AACH,eAAO,MAAM,iBAAiB,UAAW,CAAC,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAKvG,CAAA;AAED,oDAAoD;AACpD,eAAO,MAAM,sBAAsB,QAAO,MAyBzC,CAAA"}
|
|
@@ -13,16 +13,19 @@ const parseLocalStorage = (lsKey) => {
|
|
|
13
13
|
const getLocalStorageVersion = () => {
|
|
14
14
|
const collectionStr = localStorage.getItem('collection');
|
|
15
15
|
const dataVersion = localStorage.getItem(DATA_VERSION_LS_LEY);
|
|
16
|
-
if (dataVersion)
|
|
16
|
+
if (dataVersion) {
|
|
17
17
|
return dataVersion;
|
|
18
|
+
}
|
|
18
19
|
// No flatted means first version
|
|
19
|
-
if (!collectionStr?.length || collectionStr?.[0] === '{')
|
|
20
|
+
if (!collectionStr?.length || collectionStr?.[0] === '{') {
|
|
20
21
|
return '0.0.0';
|
|
22
|
+
}
|
|
21
23
|
// Flatted + types means > 2.1.0 but we should have a data version
|
|
22
24
|
try {
|
|
23
25
|
const [collection] = Object.values(parse(collectionStr) ?? {});
|
|
24
|
-
if (collection?.type === 'collection')
|
|
26
|
+
if (collection?.type === 'collection') {
|
|
25
27
|
return '2.1.0';
|
|
28
|
+
}
|
|
26
29
|
return '0.0.0';
|
|
27
30
|
}
|
|
28
31
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../../src/migrations/migrator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEpE,6CAA6C;AAC7C,eAAO,MAAM,QAAQ,QAAO,OAAO,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../../src/migrations/migrator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEpE,6CAA6C;AAC7C,eAAO,MAAM,QAAQ,QAAO,OAAO,CAAC,WAAW,CAoD9C,CAAA"}
|
|
@@ -23,20 +23,25 @@ const migrator = () => {
|
|
|
23
23
|
workspaces: parseLocalStorage('workspace'),
|
|
24
24
|
};
|
|
25
25
|
// 0.0.0 -> 2.1.0 migration
|
|
26
|
-
if (semverLessThan(dataVersion, '2.1.0'))
|
|
26
|
+
if (semverLessThan(dataVersion, '2.1.0')) {
|
|
27
27
|
data = migrate_v_2_1_0(data);
|
|
28
|
+
}
|
|
28
29
|
// 2.1.0 -> 2.2.0 migration
|
|
29
|
-
if (semverLessThan(dataVersion, '2.2.0'))
|
|
30
|
+
if (semverLessThan(dataVersion, '2.2.0')) {
|
|
30
31
|
data = migrate_v_2_2_0(data);
|
|
32
|
+
}
|
|
31
33
|
// 2.2.0 -> 2.3.0 migration
|
|
32
|
-
if (semverLessThan(dataVersion, '2.3.0'))
|
|
34
|
+
if (semverLessThan(dataVersion, '2.3.0')) {
|
|
33
35
|
data = migrate_v_2_3_0(data);
|
|
36
|
+
}
|
|
34
37
|
// 2.3.0 -> 2.4.0 migration
|
|
35
|
-
if (semverLessThan(dataVersion, '2.4.0'))
|
|
38
|
+
if (semverLessThan(dataVersion, '2.4.0')) {
|
|
36
39
|
data = migrate_v_2_4_0(data);
|
|
40
|
+
}
|
|
37
41
|
// 2.4.0 -> 2.5.0 migration
|
|
38
|
-
if (semverLessThan(dataVersion, '2.5.0'))
|
|
42
|
+
if (semverLessThan(dataVersion, '2.5.0')) {
|
|
39
43
|
data = migrate_v_2_5_0(data);
|
|
44
|
+
}
|
|
40
45
|
// Convert to data array
|
|
41
46
|
data = {
|
|
42
47
|
collections: Object.values(data.collections),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../src/migrations/semver.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,SAAS,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../src/migrations/semver.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,SAAS,MAAM,KAAG,OAyB5D,CAAA"}
|
|
@@ -4,19 +4,23 @@
|
|
|
4
4
|
const semverLessThan = (left, right) => {
|
|
5
5
|
// Parse the strings into numbers
|
|
6
6
|
const parseSemver = (version) => {
|
|
7
|
-
const [major, minor = 0, patch = 0] = version.split('.').map((part) => parseInt(part, 10));
|
|
7
|
+
const [major, minor = 0, patch = 0] = version.split('.').map((part) => Number.parseInt(part, 10));
|
|
8
8
|
return { major, minor, patch };
|
|
9
9
|
};
|
|
10
10
|
const { major: major1, minor: minor1, patch: patch1 } = parseSemver(left);
|
|
11
11
|
const { major: major2, minor: minor2, patch: patch2 } = parseSemver(right);
|
|
12
|
-
if (major1 < major2)
|
|
12
|
+
if (major1 < major2) {
|
|
13
13
|
return true;
|
|
14
|
-
|
|
14
|
+
}
|
|
15
|
+
if (major1 > major2) {
|
|
15
16
|
return false;
|
|
16
|
-
|
|
17
|
+
}
|
|
18
|
+
if (minor1 < minor2) {
|
|
17
19
|
return true;
|
|
18
|
-
|
|
20
|
+
}
|
|
21
|
+
if (minor1 > minor2) {
|
|
19
22
|
return false;
|
|
23
|
+
}
|
|
20
24
|
return patch1 < patch2;
|
|
21
25
|
};
|
|
22
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.1.0/migration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,SAAU,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.1.0/migration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,SAAU,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC;;;;;;;;;;CA0UxE,CAAA"}
|
|
@@ -35,25 +35,28 @@ const migrate_v_2_1_0 = (data) => {
|
|
|
35
35
|
});
|
|
36
36
|
/** Migrate values from old securitySchemes to the new auth */
|
|
37
37
|
const migrateAuth = (scheme) => {
|
|
38
|
-
if (scheme.type === 'apiKey')
|
|
38
|
+
if (scheme.type === 'apiKey') {
|
|
39
39
|
// ApiKey
|
|
40
40
|
return { type: 'apiKey', name: scheme.name, value: scheme.value ?? '' };
|
|
41
|
+
}
|
|
41
42
|
// HTTP
|
|
42
|
-
if (scheme.type === 'http')
|
|
43
|
+
if (scheme.type === 'http') {
|
|
43
44
|
return {
|
|
44
45
|
type: 'http',
|
|
45
46
|
username: scheme.value ?? '',
|
|
46
47
|
password: scheme.secondValue ?? '',
|
|
47
48
|
token: scheme.value ?? '',
|
|
48
49
|
};
|
|
50
|
+
}
|
|
49
51
|
// Oauth2 Implicit
|
|
50
|
-
if (scheme.type === 'oauth2' && scheme.flow.type === 'implicit')
|
|
52
|
+
if (scheme.type === 'oauth2' && scheme.flow.type === 'implicit') {
|
|
51
53
|
return {
|
|
52
54
|
type: 'oauth-implicit',
|
|
53
55
|
token: scheme.flow.token ?? '',
|
|
54
56
|
};
|
|
57
|
+
}
|
|
55
58
|
// Oauth2 Password
|
|
56
|
-
if (scheme.type === 'oauth2' && scheme.flow.type === 'password')
|
|
59
|
+
if (scheme.type === 'oauth2' && scheme.flow.type === 'password') {
|
|
57
60
|
return {
|
|
58
61
|
type: 'oauth-password',
|
|
59
62
|
token: scheme.flow.token ?? '',
|
|
@@ -61,20 +64,23 @@ const migrate_v_2_1_0 = (data) => {
|
|
|
61
64
|
password: scheme.flow.secondValue ?? '',
|
|
62
65
|
clientSecret: scheme.flow.clientSecret ?? '',
|
|
63
66
|
};
|
|
67
|
+
}
|
|
64
68
|
// Oauth2 clientCredentials
|
|
65
|
-
if (scheme.type === 'oauth2' && scheme.flow.type === 'clientCredentials')
|
|
69
|
+
if (scheme.type === 'oauth2' && scheme.flow.type === 'clientCredentials') {
|
|
66
70
|
return {
|
|
67
71
|
type: 'oauth-clientCredentials',
|
|
68
72
|
token: scheme.flow.token ?? '',
|
|
69
73
|
clientSecret: scheme.flow.clientSecret ?? '',
|
|
70
74
|
};
|
|
75
|
+
}
|
|
71
76
|
// Oauth2 Authorization Code
|
|
72
|
-
if (scheme.type === 'oauth2' && scheme.flow.type === 'authorizationCode')
|
|
77
|
+
if (scheme.type === 'oauth2' && scheme.flow.type === 'authorizationCode') {
|
|
73
78
|
return {
|
|
74
79
|
type: 'oauth-authorizationCode',
|
|
75
80
|
token: scheme.flow.token ?? '',
|
|
76
81
|
clientSecret: scheme.flow.clientSecret ?? '',
|
|
77
82
|
};
|
|
83
|
+
}
|
|
78
84
|
// Default - should not get hit
|
|
79
85
|
return {
|
|
80
86
|
type: 'apiKey',
|
|
@@ -95,8 +101,9 @@ const migrate_v_2_1_0 = (data) => {
|
|
|
95
101
|
// Migrate auth
|
|
96
102
|
const auth = securitySchemes.reduce((_prev, uid) => {
|
|
97
103
|
const scheme = oldData.securitySchemes[uid];
|
|
98
|
-
if (scheme?.uid && _prev)
|
|
104
|
+
if (scheme?.uid && _prev) {
|
|
99
105
|
_prev[uid] = migrateAuth(scheme);
|
|
106
|
+
}
|
|
100
107
|
return _prev;
|
|
101
108
|
}, {});
|
|
102
109
|
prev[c.uid] = {
|
|
@@ -168,25 +175,28 @@ const migrate_v_2_1_0 = (data) => {
|
|
|
168
175
|
selectedScopes: flow.selectedScopes || [],
|
|
169
176
|
scopes: flow.scopes || {},
|
|
170
177
|
};
|
|
171
|
-
if (flow.type === 'implicit')
|
|
178
|
+
if (flow.type === 'implicit') {
|
|
172
179
|
return {
|
|
173
180
|
...flow,
|
|
174
181
|
...base,
|
|
175
182
|
'type': 'implicit',
|
|
176
183
|
'x-scalar-redirect-uri': ('redirectUri' in flow ? flow.redirectUri : '') || '',
|
|
177
184
|
};
|
|
178
|
-
|
|
185
|
+
}
|
|
186
|
+
if (flow.type === 'password') {
|
|
179
187
|
return {
|
|
180
188
|
...flow,
|
|
181
189
|
...base,
|
|
182
190
|
tokenUrl: flow.tokenUrl || '',
|
|
183
191
|
};
|
|
184
|
-
|
|
192
|
+
}
|
|
193
|
+
if (flow.type === 'clientCredentials') {
|
|
185
194
|
return {
|
|
186
195
|
...flow,
|
|
187
196
|
...base,
|
|
188
197
|
tokenUrl: flow.tokenUrl || '',
|
|
189
198
|
};
|
|
199
|
+
}
|
|
190
200
|
return {
|
|
191
201
|
...flow,
|
|
192
202
|
...base,
|
|
@@ -207,7 +217,7 @@ const migrate_v_2_1_0 = (data) => {
|
|
|
207
217
|
case 'oauth2':
|
|
208
218
|
return camelToTitleWords(scheme.flow.type);
|
|
209
219
|
case 'openIdConnect':
|
|
210
|
-
return
|
|
220
|
+
return 'Open ID Connect';
|
|
211
221
|
default:
|
|
212
222
|
return 'None';
|
|
213
223
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.2.0/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAkGhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,SAAU,OAAO,CAAC,UAAU,KAAG,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.2.0/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAkGhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,SAAU,OAAO,CAAC,UAAU,KAAG,OAAO,CAAC,UA6BlE,CAAA"}
|
|
@@ -89,11 +89,13 @@ const migrate_v_2_2_0 = (data) => {
|
|
|
89
89
|
const securitySchemes = Object.values(data.securitySchemes).reduce((prev, s) => {
|
|
90
90
|
const collection = Object.values(data.collections).find((c) => c.securitySchemes.includes(s.uid));
|
|
91
91
|
const auth = collection?.auth?.[s.uid];
|
|
92
|
-
if (!auth)
|
|
92
|
+
if (!auth) {
|
|
93
93
|
return prev;
|
|
94
|
+
}
|
|
94
95
|
const newScheme = migrateSecurityScheme(s, auth);
|
|
95
|
-
if (newScheme)
|
|
96
|
+
if (newScheme) {
|
|
96
97
|
prev[s.uid] = newScheme;
|
|
98
|
+
}
|
|
97
99
|
return prev;
|
|
98
100
|
}, {});
|
|
99
101
|
// No changes to servers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExampleFromSchema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getExampleFromSchema.ts"],"names":[],"mappings":"AAyDA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;OAGG;IACH,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,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,UACM,MAAM,iBACE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAC3B,MAAM,KACZ,
|
|
1
|
+
{"version":3,"file":"getExampleFromSchema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getExampleFromSchema.ts"],"names":[],"mappings":"AAyDA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;OAGG;IACH,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,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,UACM,MAAM,iBACE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAC3B,MAAM,KACZ,GA8QF,CAAA"}
|
|
@@ -80,7 +80,7 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
80
80
|
if (value !== undefined) {
|
|
81
81
|
// Type-casting
|
|
82
82
|
if (schema.type === 'number' || schema.type === 'integer') {
|
|
83
|
-
return parseInt(value, 10);
|
|
83
|
+
return Number.parseInt(value, 10);
|
|
84
84
|
}
|
|
85
85
|
return cache(schema, value);
|
|
86
86
|
}
|
|
@@ -185,13 +185,11 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
185
185
|
const mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema);
|
|
186
186
|
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
|
|
187
187
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
|
|
194
|
-
}
|
|
188
|
+
// For non-objects (like strings), collect all examples
|
|
189
|
+
const examples = schema.items.allOf
|
|
190
|
+
.map((item) => getExampleFromSchema(item, options, level + 1, schema))
|
|
191
|
+
.filter((item) => item !== undefined);
|
|
192
|
+
return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
|
|
195
193
|
}
|
|
196
194
|
// Handle other rules (anyOf, oneOf)
|
|
197
195
|
const rules = ['anyOf', 'oneOf'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getParametersFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getParametersFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAI/E;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc,GAC3B,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"getParametersFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getParametersFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAI/E;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc,GAC3B,aAAa,EAAE,CAiCjB"}
|
|
@@ -29,11 +29,13 @@ function getParametersFromOperation(operation, where, requiredOnly = true) {
|
|
|
29
29
|
}));
|
|
30
30
|
return params.sort((a, b) => {
|
|
31
31
|
// Move a up if a is required and b is not
|
|
32
|
-
if (a.required && !b.required)
|
|
32
|
+
if (a.required && !b.required) {
|
|
33
33
|
return -1;
|
|
34
|
+
}
|
|
34
35
|
// Move b up if b is required and a is not
|
|
35
|
-
if (!a.required && b.required)
|
|
36
|
+
if (!a.required && b.required) {
|
|
36
37
|
return 1;
|
|
38
|
+
}
|
|
37
39
|
// Keep original order if both have the same required status
|
|
38
40
|
return 0;
|
|
39
41
|
});
|
|
@@ -17,7 +17,9 @@ export declare const parseSchema: (spec: string | UnknownObject, { shouldLoad }?
|
|
|
17
17
|
}>;
|
|
18
18
|
/** Converts selected security requirements to uids */
|
|
19
19
|
export declare const getSelectedSecuritySchemeUids: (securityRequirements: (string | string[])[], preferredSecurityNames: (string | string[])[] | undefined, securitySchemeMap: Record<string, SecurityScheme["uid"]>) => SelectedSecuritySchemeUids;
|
|
20
|
-
|
|
20
|
+
/** Create a "uid" from a slug */
|
|
21
|
+
export declare const getSlugUid: (slug: string) => Collection["uid"];
|
|
22
|
+
export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> & Pick<ApiReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers' | 'slug'> & {
|
|
21
23
|
/** Sets the preferred security scheme on the collection instead of the requests */
|
|
22
24
|
setCollectionSecurity?: boolean;
|
|
23
25
|
/** Call the load step from the parser */
|
|
@@ -36,7 +38,7 @@ export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' |
|
|
|
36
38
|
* - Proper linking between related components
|
|
37
39
|
* - Easy lookup and reference of dependent entities
|
|
38
40
|
*/
|
|
39
|
-
export declare function importSpecToWorkspace(spec: string | UnknownObject, { authentication, baseServerURL, documentUrl, servers: configuredServers, setCollectionSecurity, shouldLoad, watchMode, }?: ImportSpecToWorkspaceArgs): Promise<{
|
|
41
|
+
export declare function importSpecToWorkspace(spec: string | UnknownObject, { authentication, baseServerURL, documentUrl, servers: configuredServers, setCollectionSecurity, slug, shouldLoad, watchMode, }?: ImportSpecToWorkspaceArgs): Promise<{
|
|
40
42
|
error: false;
|
|
41
43
|
collection: Collection;
|
|
42
44
|
requests: Request[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAMjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,mFAAmF;AACnF,eAAO,MAAM,WAAW,SAAgB,MAAM,GAAG,aAAa;;;
|
|
1
|
+
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,0BAA0B,CAAA;AAMjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,mFAAmF;AACnF,eAAO,MAAM,WAAW,SAAgB,MAAM,GAAG,aAAa;;;IAoC1D;;;OAGG;YAC8C,WAAW,CAAC,QAAQ;;EAGxE,CAAA;AAED,sDAAsD;AACtD,eAAO,MAAM,6BAA6B,yBAClB,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,0BACnB,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,iCAC1B,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,KACvD,0BAWF,CAAA;AAED,iCAAiC;AACjC,eAAO,MAAM,UAAU,SAAU,MAAM,KAA2B,UAAU,CAAC,KAAK,CAAC,CAAA;AAEnF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,WAAW,CAAC,GAC1F,IAAI,CAAC,yBAAyB,EAAE,gBAAgB,GAAG,eAAe,GAAG,SAAS,GAAG,MAAM,CAAC,GAAG;IACzF,mFAAmF;IACnF,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,yCAAyC;IACzC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,GAAG,aAAa,EAC5B,EACE,cAAc,EACd,aAAa,EACb,WAAW,EACX,OAAO,EAAE,iBAAiB,EAC1B,qBAA6B,EAC7B,IAAI,EACJ,UAAU,EACV,SAAiB,GAClB,GAAE,yBAA8B,GAChC,OAAO,CACN;IACE,KAAK,EAAE,KAAK,CAAA;IACZ,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAA;IAC5B,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,eAAe,EAAE,cAAc,EAAE,CAAA;CAClC,GACD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,SAAS,CAAA;CAAE,CACnE,CA0VA;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,GAAG,SAAS,EAC/C,EAAE,aAAa,EAAE,GAAE,IAAI,CAAC,yBAAyB,EAAE,eAAe,CAAM,GACvE,MAAM,EAAE,CA0CV"}
|
|
@@ -39,8 +39,9 @@ const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
|
39
39
|
}
|
|
40
40
|
const { specification } = upgrade(filesystem);
|
|
41
41
|
const { schema, errors: derefErrors = [] } = await dereference(specification);
|
|
42
|
-
if (!schema)
|
|
42
|
+
if (!schema) {
|
|
43
43
|
console.warn('[@scalar/oas-utils] OpenAPI Parser Warning: Schema is undefined');
|
|
44
|
+
}
|
|
44
45
|
return {
|
|
45
46
|
/**
|
|
46
47
|
* Temporary fix for the parser returning an empty array
|
|
@@ -60,6 +61,8 @@ const getSelectedSecuritySchemeUids = (securityRequirements, preferredSecurityNa
|
|
|
60
61
|
.filter(isDefined);
|
|
61
62
|
return uids;
|
|
62
63
|
};
|
|
64
|
+
/** Create a "uid" from a slug */
|
|
65
|
+
const getSlugUid = (slug) => `slug-uid-${slug}`;
|
|
63
66
|
/**
|
|
64
67
|
* Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
|
|
65
68
|
*
|
|
@@ -73,11 +76,12 @@ const getSelectedSecuritySchemeUids = (securityRequirements, preferredSecurityNa
|
|
|
73
76
|
* - Proper linking between related components
|
|
74
77
|
* - Easy lookup and reference of dependent entities
|
|
75
78
|
*/
|
|
76
|
-
async function importSpecToWorkspace(spec, { authentication, baseServerURL, documentUrl, servers: configuredServers, setCollectionSecurity = false, shouldLoad, watchMode = false, } = {}) {
|
|
79
|
+
async function importSpecToWorkspace(spec, { authentication, baseServerURL, documentUrl, servers: configuredServers, setCollectionSecurity = false, slug, shouldLoad, watchMode = false, } = {}) {
|
|
77
80
|
const { schema, errors } = await parseSchema(spec, { shouldLoad });
|
|
78
81
|
const importWarnings = [...errors.map((e) => e.message)];
|
|
79
|
-
if (!schema)
|
|
82
|
+
if (!schema) {
|
|
80
83
|
return { importWarnings, error: true, collection: undefined };
|
|
84
|
+
}
|
|
81
85
|
// ---------------------------------------------------------------------------
|
|
82
86
|
// Some entities will be broken out as individual lists for modification in the workspace
|
|
83
87
|
const start = performance.now();
|
|
@@ -112,37 +116,44 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
112
116
|
if (payload.type === 'oauth2' && payload.flows) {
|
|
113
117
|
const flowKeys = Object.keys(payload.flows);
|
|
114
118
|
flowKeys.forEach((key) => {
|
|
115
|
-
if (!payload.flows?.[key])
|
|
119
|
+
if (!payload.flows?.[key]) {
|
|
116
120
|
return;
|
|
121
|
+
}
|
|
117
122
|
const flow = payload.flows[key];
|
|
118
123
|
// Set the type
|
|
119
124
|
flow.type = key;
|
|
120
125
|
// Prefill values from authorization config
|
|
121
126
|
if (authentication?.oAuth2) {
|
|
122
|
-
if (authentication.oAuth2.accessToken)
|
|
127
|
+
if (authentication.oAuth2.accessToken) {
|
|
123
128
|
flow.token = authentication.oAuth2.accessToken;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
flow
|
|
129
|
+
}
|
|
130
|
+
if (authentication.oAuth2.clientId) {
|
|
131
|
+
flow['x-scalar-client-id'] = authentication.oAuth2.clientId;
|
|
127
132
|
}
|
|
128
133
|
if (authentication.oAuth2.scopes) {
|
|
129
134
|
flow.selectedScopes = authentication.oAuth2.scopes;
|
|
130
|
-
|
|
135
|
+
}
|
|
136
|
+
if (flow.type === 'password') {
|
|
137
|
+
flow.username = authentication.oAuth2.username;
|
|
138
|
+
flow.password = authentication.oAuth2.password;
|
|
131
139
|
}
|
|
132
140
|
}
|
|
133
141
|
// Convert scopes to an object
|
|
134
|
-
if (Array.isArray(flow.scopes))
|
|
142
|
+
if (Array.isArray(flow.scopes)) {
|
|
135
143
|
flow.scopes = flow.scopes.reduce((prev, s) => ({ ...prev, [s]: '' }), {});
|
|
144
|
+
}
|
|
136
145
|
// Handle x-defaultClientId
|
|
137
|
-
if (flow['x-defaultClientId'])
|
|
146
|
+
if (flow['x-defaultClientId']) {
|
|
138
147
|
flow['x-scalar-client-id'] = flow['x-defaultClientId'];
|
|
148
|
+
}
|
|
139
149
|
});
|
|
140
150
|
}
|
|
141
151
|
// Otherwise we just prefill
|
|
142
152
|
else if (authentication) {
|
|
143
153
|
// ApiKey
|
|
144
|
-
if (payload.type === 'apiKey' && authentication.apiKey?.token)
|
|
154
|
+
if (payload.type === 'apiKey' && authentication.apiKey?.token) {
|
|
145
155
|
payload.value = authentication.apiKey.token;
|
|
156
|
+
}
|
|
146
157
|
// HTTP
|
|
147
158
|
else if (payload.type === 'http') {
|
|
148
159
|
if (payload.scheme === 'basic' && authentication.http?.basic) {
|
|
@@ -162,8 +173,9 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
162
173
|
}
|
|
163
174
|
}
|
|
164
175
|
const scheme = schemaModel(payload, securitySchemeSchema, false);
|
|
165
|
-
if (!scheme)
|
|
176
|
+
if (!scheme) {
|
|
166
177
|
importWarnings.push(`Security scheme ${nameKey} is invalid.`);
|
|
178
|
+
}
|
|
167
179
|
return scheme;
|
|
168
180
|
})
|
|
169
181
|
.filter((v) => !!v);
|
|
@@ -176,8 +188,9 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
176
188
|
// REQUEST HANDLING
|
|
177
189
|
keysOf(schema.paths ?? {}).forEach((pathString) => {
|
|
178
190
|
const path = schema?.paths?.[pathString];
|
|
179
|
-
if (!path)
|
|
191
|
+
if (!path) {
|
|
180
192
|
return;
|
|
193
|
+
}
|
|
181
194
|
// Path level servers must be saved
|
|
182
195
|
const pathServers = serverSchema.array().parse(path.servers ?? []);
|
|
183
196
|
servers.push(...pathServers);
|
|
@@ -228,7 +241,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
228
241
|
}
|
|
229
242
|
// Add list of UIDs to associate security schemes
|
|
230
243
|
// As per the spec if there is operation level security we ignore the top level requirements
|
|
231
|
-
if (operationSecurity?.length)
|
|
244
|
+
if (operationSecurity?.length) {
|
|
232
245
|
requestPayload.security = operationSecurity.map((s) => {
|
|
233
246
|
const keys = Object.keys(s);
|
|
234
247
|
// Handle the case of {} for optional
|
|
@@ -240,12 +253,15 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
240
253
|
}
|
|
241
254
|
return s;
|
|
242
255
|
});
|
|
256
|
+
}
|
|
243
257
|
// Save parse the request
|
|
244
258
|
const request = schemaModel(requestPayload, requestSchema, false);
|
|
245
|
-
if (!request)
|
|
259
|
+
if (!request) {
|
|
246
260
|
importWarnings.push(`${method} Request at ${path} is invalid.`);
|
|
247
|
-
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
248
263
|
requests.push(request);
|
|
264
|
+
}
|
|
249
265
|
});
|
|
250
266
|
});
|
|
251
267
|
// ---------------------------------------------------------------------------
|
|
@@ -310,7 +326,10 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
310
326
|
const selectedSecuritySchemeUids = (securityRequirements.length || preferredSecurityNames?.length) && setCollectionSecurity
|
|
311
327
|
? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)
|
|
312
328
|
: [];
|
|
329
|
+
// Set the uid as a prefixed slug if we have one
|
|
330
|
+
const slugObj = slug?.length ? { uid: getSlugUid(slug) } : {};
|
|
313
331
|
const collection = collectionSchema.parse({
|
|
332
|
+
...slugObj,
|
|
314
333
|
...schema,
|
|
315
334
|
watchMode,
|
|
316
335
|
documentUrl,
|
|
@@ -347,8 +366,9 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
347
366
|
* Retrieves a list of servers from an OpenAPI document and converts them to a list of Server entities.
|
|
348
367
|
*/
|
|
349
368
|
function getServersFromOpenApiDocument(servers, { baseServerURL } = {}) {
|
|
350
|
-
if (!servers || !Array.isArray(servers))
|
|
369
|
+
if (!servers || !Array.isArray(servers)) {
|
|
351
370
|
return [];
|
|
371
|
+
}
|
|
352
372
|
return servers
|
|
353
373
|
.map((server) => {
|
|
354
374
|
try {
|
|
@@ -394,4 +414,4 @@ function getFallbackUrl() {
|
|
|
394
414
|
return window.location.origin;
|
|
395
415
|
}
|
|
396
416
|
|
|
397
|
-
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema };
|
|
417
|
+
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, getSlugUid, importSpecToWorkspace, parseSchema };
|
package/dist/transforms/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, importSpecToWorkspace, parseSchema } from './import-spec.js';
|
|
1
|
+
export { getSelectedSecuritySchemeUids, getServersFromOpenApiDocument, getSlugUid, importSpecToWorkspace, parseSchema } from './import-spec.js';
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.121",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -128,8 +128,8 @@
|
|
|
128
128
|
"zod": "^3.23.8",
|
|
129
129
|
"@scalar/object-utils": "1.1.13",
|
|
130
130
|
"@scalar/openapi-types": "0.1.9",
|
|
131
|
-
"@scalar/themes": "0.9.
|
|
132
|
-
"@scalar/types": "0.1.
|
|
131
|
+
"@scalar/themes": "0.9.80",
|
|
132
|
+
"@scalar/types": "0.1.2"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
135
|
"type-fest": "^4.20.0",
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"vitest": "^1.6.0",
|
|
138
138
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
139
139
|
"@scalar/build-tooling": "0.1.17",
|
|
140
|
-
"@scalar/openapi-parser": "0.10.
|
|
140
|
+
"@scalar/openapi-parser": "0.10.11",
|
|
141
141
|
"@scalar/openapi-types": "0.1.9"
|
|
142
142
|
},
|
|
143
143
|
"scripts": {
|