@scalar/openapi-parser 0.10.14 → 0.10.15
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 +7 -0
- package/README.md +22 -0
- package/dist/lib/Validator/Validator.js +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.d.ts +1 -0
- package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -1
- package/dist/plugins/fetch-urls/fetchUrls.js +79 -7
- 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 +18 -3
- package/dist/types/index.d.ts +23 -4
- 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 +2 -1
- package/dist/utils/isFilesystem.d.ts.map +1 -1
- package/dist/utils/load/load.d.ts +11 -2
- package/dist/utils/load/load.d.ts.map +1 -1
- package/dist/utils/load/load.js +77 -38
- package/dist/utils/makeFilesystem.d.ts +18 -1
- package/dist/utils/makeFilesystem.d.ts.map +1 -1
- package/dist/utils/makeFilesystem.js +55 -9
- 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 +6 -0
- package/dist/utils/resolveReferences.d.ts.map +1 -1
- package/dist/utils/resolveReferences.js +19 -9
- package/dist/utils/upgrade.js +1 -1
- package/package.json +4 -3
|
@@ -15,6 +15,12 @@ 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;
|
|
18
24
|
};
|
|
19
25
|
/**
|
|
20
26
|
* 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;IAClE;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B,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?.content ?? entrypoint.content;
|
|
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,9 +46,18 @@ errors, options) {
|
|
|
46
46
|
}
|
|
47
47
|
resolvedSchemas.add(schema);
|
|
48
48
|
function resolveExternal(externalFile) {
|
|
49
|
-
dereference(externalFile.
|
|
49
|
+
dereference(externalFile.content, 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
|
+
}
|
|
52
61
|
while (schema.$ref !== undefined) {
|
|
53
62
|
// Find the referenced content
|
|
54
63
|
const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors);
|
|
@@ -83,9 +92,9 @@ errors, options) {
|
|
|
83
92
|
function resolveUri(
|
|
84
93
|
// 'foobar.json#/foo/bar'
|
|
85
94
|
uri, options,
|
|
86
|
-
// {
|
|
95
|
+
// { uri: './foobar.json '}
|
|
87
96
|
file,
|
|
88
|
-
// [ {
|
|
97
|
+
// [ { uri: './foobar.json '} ]
|
|
89
98
|
filesystem,
|
|
90
99
|
// a function to resolve references in external file
|
|
91
100
|
resolve, errors) {
|
|
@@ -103,11 +112,12 @@ resolve, errors) {
|
|
|
103
112
|
// Understand the URI
|
|
104
113
|
const [prefix, path] = uri.split('#', 2);
|
|
105
114
|
/** Check whether the file is pointing to itself */
|
|
106
|
-
const isDifferentFile = prefix !== file.
|
|
115
|
+
const isDifferentFile = prefix !== file.uri;
|
|
107
116
|
// External references
|
|
108
117
|
if (prefix && isDifferentFile) {
|
|
118
|
+
const absoluteUri = file.references[prefix] ?? prefix;
|
|
109
119
|
const externalReference = filesystem.find((entry) => {
|
|
110
|
-
return entry.
|
|
120
|
+
return entry.uri && entry.uri === absoluteUri;
|
|
111
121
|
});
|
|
112
122
|
if (!externalReference) {
|
|
113
123
|
if (options?.throwOnError) {
|
|
@@ -121,7 +131,7 @@ resolve, errors) {
|
|
|
121
131
|
}
|
|
122
132
|
// $ref: 'other-file.yaml'
|
|
123
133
|
if (path === undefined) {
|
|
124
|
-
return externalReference.
|
|
134
|
+
return externalReference.content;
|
|
125
135
|
}
|
|
126
136
|
// $ref: 'other-file.yaml#/foo/bar'
|
|
127
137
|
// resolve refs first before accessing properties directly
|
|
@@ -129,11 +139,11 @@ resolve, errors) {
|
|
|
129
139
|
}
|
|
130
140
|
// Pointers
|
|
131
141
|
const segments = getSegmentsFromPath(path);
|
|
132
|
-
//
|
|
142
|
+
// Internal references
|
|
133
143
|
try {
|
|
134
144
|
return segments.reduce((acc, key) => {
|
|
135
145
|
return acc[key];
|
|
136
|
-
}, file.
|
|
146
|
+
}, file.content);
|
|
137
147
|
}
|
|
138
148
|
catch (_error) {
|
|
139
149
|
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)).content);
|
|
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.15",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=18"
|
|
23
23
|
},
|
|
@@ -64,9 +64,10 @@
|
|
|
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",
|
|
67
69
|
"@scalar/build-tooling": "0.1.17",
|
|
68
|
-
"@scalar/types": "0.1.
|
|
69
|
-
"@scalar/openapi-types": "0.2.0"
|
|
70
|
+
"@scalar/types": "0.1.8"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"build": "scalar-build-rollup",
|