@scalar/openapi-parser 0.10.13 → 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 +13 -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/dist/utils/upgradeFromTwoToThree.d.ts.map +1 -1
- package/dist/utils/upgradeFromTwoToThree.js +58 -0
- 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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgradeFromTwoToThree.d.ts","sourceRoot":"","sources":["../../src/utils/upgradeFromTwoToThree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"upgradeFromTwoToThree.d.ts","sourceRoot":"","sources":["../../src/utils/upgradeFromTwoToThree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CA+PzE"}
|
|
@@ -44,6 +44,13 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
44
44
|
return schema;
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
+
specification = traverse(specification, (schema) => {
|
|
48
|
+
if (schema.type === 'file') {
|
|
49
|
+
schema.type = 'string';
|
|
50
|
+
schema.format = 'binary';
|
|
51
|
+
}
|
|
52
|
+
return schema;
|
|
53
|
+
});
|
|
47
54
|
// Paths
|
|
48
55
|
if (typeof specification.paths === 'object') {
|
|
49
56
|
for (const path in specification.paths) {
|
|
@@ -109,12 +116,21 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
109
116
|
// Remove formData parameters from the parameters array
|
|
110
117
|
operationItem.parameters = operationItem.parameters.filter((parameter) => parameter.in !== 'formData');
|
|
111
118
|
}
|
|
119
|
+
operationItem.parameters = operationItem.parameters.map((parameter) => transformParameterObject(parameter));
|
|
112
120
|
}
|
|
113
121
|
// Responses
|
|
114
122
|
if (operationItem.responses) {
|
|
115
123
|
for (const response in operationItem.responses) {
|
|
116
124
|
if (Object.hasOwn(operationItem.responses, response)) {
|
|
117
125
|
const responseItem = operationItem.responses[response];
|
|
126
|
+
if (responseItem.headers) {
|
|
127
|
+
responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {
|
|
128
|
+
return {
|
|
129
|
+
[name]: transformParameterObject(header),
|
|
130
|
+
...acc,
|
|
131
|
+
};
|
|
132
|
+
}, {});
|
|
133
|
+
}
|
|
118
134
|
if (responseItem.schema) {
|
|
119
135
|
const produces = specification.produces ?? operationItem.produces ?? ['application/json'];
|
|
120
136
|
if (typeof responseItem.content !== 'object') {
|
|
@@ -162,6 +178,14 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
162
178
|
},
|
|
163
179
|
});
|
|
164
180
|
}
|
|
181
|
+
else if ('type' in securityScheme && securityScheme.type === 'basic') {
|
|
182
|
+
Object.assign(specification.components.securitySchemes, {
|
|
183
|
+
[key]: {
|
|
184
|
+
type: 'http',
|
|
185
|
+
scheme: 'basic',
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
165
189
|
else {
|
|
166
190
|
Object.assign(specification.components.securitySchemes, {
|
|
167
191
|
[key]: securityScheme,
|
|
@@ -173,5 +197,39 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
173
197
|
}
|
|
174
198
|
return specification;
|
|
175
199
|
}
|
|
200
|
+
function transformItemsObject(obj) {
|
|
201
|
+
const schemaProperties = [
|
|
202
|
+
'type',
|
|
203
|
+
'format',
|
|
204
|
+
'items',
|
|
205
|
+
'maximum',
|
|
206
|
+
'exclusiveMaximum',
|
|
207
|
+
'minimum',
|
|
208
|
+
'exclusiveMinimum',
|
|
209
|
+
'maxLength',
|
|
210
|
+
'minLength',
|
|
211
|
+
'pattern',
|
|
212
|
+
'maxItems',
|
|
213
|
+
'minItems',
|
|
214
|
+
'uniqueItems',
|
|
215
|
+
'enum',
|
|
216
|
+
'multipleOf',
|
|
217
|
+
];
|
|
218
|
+
return schemaProperties.reduce((acc, property) => {
|
|
219
|
+
if (Object.hasOwn(obj, property)) {
|
|
220
|
+
acc[property] = obj[property];
|
|
221
|
+
delete obj[property];
|
|
222
|
+
}
|
|
223
|
+
return acc;
|
|
224
|
+
}, {});
|
|
225
|
+
}
|
|
226
|
+
function transformParameterObject(parameter) {
|
|
227
|
+
delete parameter.collectionFormat;
|
|
228
|
+
delete parameter.default;
|
|
229
|
+
return {
|
|
230
|
+
schema: transformItemsObject(parameter),
|
|
231
|
+
...parameter,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
176
234
|
|
|
177
235
|
export { upgradeFromTwoToThree };
|
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",
|