@scalar/openapi-parser 0.10.15 → 0.10.16
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 +6 -0
- package/README.md +0 -22
- package/dist/lib/Validator/Validator.js +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.d.ts +0 -1
- package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.js +7 -79
- package/dist/plugins/fetch-urls/index.d.ts +1 -1
- package/dist/plugins/fetch-urls/index.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/index.js +1 -1
- package/dist/plugins/read-files/index.d.ts +1 -1
- package/dist/plugins/read-files/index.d.ts.map +1 -1
- package/dist/plugins/read-files/readFiles.d.ts.map +1 -1
- package/dist/plugins/read-files/readFiles.js +3 -18
- package/dist/types/index.d.ts +4 -23
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/dereference.js +2 -2
- package/dist/utils/filter.js +1 -1
- package/dist/utils/isFilesystem.d.ts +1 -2
- package/dist/utils/isFilesystem.d.ts.map +1 -1
- package/dist/utils/load/load.d.ts +2 -11
- package/dist/utils/load/load.d.ts.map +1 -1
- package/dist/utils/load/load.js +38 -77
- package/dist/utils/makeFilesystem.d.ts +1 -18
- package/dist/utils/makeFilesystem.d.ts.map +1 -1
- package/dist/utils/makeFilesystem.js +9 -55
- package/dist/utils/openapi/actions/details.js +1 -1
- package/dist/utils/openapi/actions/toJson.js +1 -1
- package/dist/utils/openapi/actions/toYaml.js +1 -1
- package/dist/utils/openapi/commands/loadCommand.d.ts +180 -180
- package/dist/utils/resolveReferences.d.ts +0 -6
- package/dist/utils/resolveReferences.d.ts.map +1 -1
- package/dist/utils/resolveReferences.js +9 -19
- package/dist/utils/upgrade.js +1 -1
- package/package.json +3 -4
|
@@ -15,12 +15,6 @@ export type ResolveReferencesOptions = ThrowOnErrorOption & {
|
|
|
15
15
|
schema: AnyObject;
|
|
16
16
|
ref: string;
|
|
17
17
|
}) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Whether to resolve internal references.
|
|
20
|
-
*
|
|
21
|
-
* @default true
|
|
22
|
-
*/
|
|
23
|
-
resolveInternalRefs?: boolean;
|
|
24
18
|
};
|
|
25
19
|
/**
|
|
26
20
|
* Takes a specification and resolves all references.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveReferences.d.ts","sourceRoot":"","sources":["../../src/utils/resolveReferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAehH,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"resolveReferences.d.ts","sourceRoot":"","sources":["../../src/utils/resolveReferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAehH,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;CACnE,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAE/B,KAAK,EAAE,SAAS,GAAG,UAAU,EAE7B,OAAO,CAAC,EAAE,wBAAwB,EAElC,IAAI,CAAC,EAAE,eAAe,EAEtB,MAAM,GAAE,WAAW,EAAO,GACzB,uBAAuB,CA0BzB"}
|
|
@@ -21,7 +21,7 @@ errors = []) {
|
|
|
21
21
|
const filesystem = makeFilesystem(clonedInput);
|
|
22
22
|
// Get the main file
|
|
23
23
|
const entrypoint = getEntrypoint(filesystem);
|
|
24
|
-
const finalInput = file?.
|
|
24
|
+
const finalInput = file?.specification ?? entrypoint.specification;
|
|
25
25
|
// Recursively resolve all references
|
|
26
26
|
dereference(finalInput, filesystem, file ?? entrypoint, new WeakSet(), errors, options);
|
|
27
27
|
// Remove duplicats (according to message) from errors
|
|
@@ -46,18 +46,9 @@ errors, options) {
|
|
|
46
46
|
}
|
|
47
47
|
resolvedSchemas.add(schema);
|
|
48
48
|
function resolveExternal(externalFile) {
|
|
49
|
-
dereference(externalFile.
|
|
49
|
+
dereference(externalFile.specification, filesystem, externalFile, resolvedSchemas, errors, options);
|
|
50
50
|
return externalFile;
|
|
51
51
|
}
|
|
52
|
-
// Skip internal reference resolution if resolveInternalRefs is false
|
|
53
|
-
const skipReference =
|
|
54
|
-
// Only if the option is set …
|
|
55
|
-
options?.resolveInternalRefs === false &&
|
|
56
|
-
// and it’s obviously internal
|
|
57
|
-
schema.$ref?.startsWith('#');
|
|
58
|
-
if (skipReference) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
52
|
while (schema.$ref !== undefined) {
|
|
62
53
|
// Find the referenced content
|
|
63
54
|
const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors);
|
|
@@ -92,9 +83,9 @@ errors, options) {
|
|
|
92
83
|
function resolveUri(
|
|
93
84
|
// 'foobar.json#/foo/bar'
|
|
94
85
|
uri, options,
|
|
95
|
-
// {
|
|
86
|
+
// { filename: './foobar.json '}
|
|
96
87
|
file,
|
|
97
|
-
// [ {
|
|
88
|
+
// [ { filename: './foobar.json '} ]
|
|
98
89
|
filesystem,
|
|
99
90
|
// a function to resolve references in external file
|
|
100
91
|
resolve, errors) {
|
|
@@ -112,12 +103,11 @@ resolve, errors) {
|
|
|
112
103
|
// Understand the URI
|
|
113
104
|
const [prefix, path] = uri.split('#', 2);
|
|
114
105
|
/** Check whether the file is pointing to itself */
|
|
115
|
-
const isDifferentFile = prefix !== file.
|
|
106
|
+
const isDifferentFile = prefix !== file.filename;
|
|
116
107
|
// External references
|
|
117
108
|
if (prefix && isDifferentFile) {
|
|
118
|
-
const absoluteUri = file.references[prefix] ?? prefix;
|
|
119
109
|
const externalReference = filesystem.find((entry) => {
|
|
120
|
-
return entry.
|
|
110
|
+
return entry.filename === prefix;
|
|
121
111
|
});
|
|
122
112
|
if (!externalReference) {
|
|
123
113
|
if (options?.throwOnError) {
|
|
@@ -131,7 +121,7 @@ resolve, errors) {
|
|
|
131
121
|
}
|
|
132
122
|
// $ref: 'other-file.yaml'
|
|
133
123
|
if (path === undefined) {
|
|
134
|
-
return externalReference.
|
|
124
|
+
return externalReference.specification;
|
|
135
125
|
}
|
|
136
126
|
// $ref: 'other-file.yaml#/foo/bar'
|
|
137
127
|
// resolve refs first before accessing properties directly
|
|
@@ -139,11 +129,11 @@ resolve, errors) {
|
|
|
139
129
|
}
|
|
140
130
|
// Pointers
|
|
141
131
|
const segments = getSegmentsFromPath(path);
|
|
142
|
-
//
|
|
132
|
+
// Try to find the URI
|
|
143
133
|
try {
|
|
144
134
|
return segments.reduce((acc, key) => {
|
|
145
135
|
return acc[key];
|
|
146
|
-
}, file.
|
|
136
|
+
}, file.specification);
|
|
147
137
|
}
|
|
148
138
|
catch (_error) {
|
|
149
139
|
if (options?.throwOnError) {
|
package/dist/utils/upgrade.js
CHANGED
|
@@ -15,7 +15,7 @@ function upgrade(value) {
|
|
|
15
15
|
}
|
|
16
16
|
const upgraders = [upgradeFromTwoToThree, upgradeFromThreeToThreeOne];
|
|
17
17
|
// TODO: Run upgrade over the whole filesystem
|
|
18
|
-
const result = upgraders.reduce((currentSpecification, upgrader) => upgrader(currentSpecification), getEntrypoint(makeFilesystem(value)).
|
|
18
|
+
const result = upgraders.reduce((currentSpecification, upgrader) => upgrader(currentSpecification), getEntrypoint(makeFilesystem(value)).specification);
|
|
19
19
|
return {
|
|
20
20
|
specification: result,
|
|
21
21
|
// TODO: Make dynamic
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"parser",
|
|
18
18
|
"typescript"
|
|
19
19
|
],
|
|
20
|
-
"version": "0.10.
|
|
20
|
+
"version": "0.10.16",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=18"
|
|
23
23
|
},
|
|
@@ -64,10 +64,9 @@
|
|
|
64
64
|
"json-to-ast": "^2.1.0",
|
|
65
65
|
"just-diff": "^6.0.2",
|
|
66
66
|
"tinybench": "^2.8.0",
|
|
67
|
-
"vite": "^5.4.10",
|
|
68
|
-
"@scalar/openapi-types": "0.2.0",
|
|
69
67
|
"@scalar/build-tooling": "0.1.17",
|
|
70
|
-
"@scalar/types": "0.1.8"
|
|
68
|
+
"@scalar/types": "0.1.8",
|
|
69
|
+
"@scalar/openapi-types": "0.2.0"
|
|
71
70
|
},
|
|
72
71
|
"scripts": {
|
|
73
72
|
"build": "scalar-build-rollup",
|