@scalar/openapi-upgrader 0.2.2 → 0.2.4
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrade-from-two-to-three.d.ts","sourceRoot":"","sources":["../../src/2.0-to-3.0/upgrade-from-two-to-three.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"upgrade-from-two-to-three.d.ts","sourceRoot":"","sources":["../../src/2.0-to-3.0/upgrade-from-two-to-three.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AA8LxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CAoczE"}
|
|
@@ -22,6 +22,73 @@ function isNamedExamplesCollection(value) {
|
|
|
22
22
|
return (isNonEmptyObject(value) &&
|
|
23
23
|
Object.values(value).every((v) => typeof v === 'object' && v !== null && !Array.isArray(v)));
|
|
24
24
|
}
|
|
25
|
+
/** Checks if a schema is empty (no meaningful properties defined) */
|
|
26
|
+
function isEmptySchema(schema) {
|
|
27
|
+
if (typeof schema !== 'object' || schema === null) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const s = schema;
|
|
31
|
+
const substantiveValidationKeywords = [
|
|
32
|
+
'enum',
|
|
33
|
+
'const',
|
|
34
|
+
'not',
|
|
35
|
+
'format',
|
|
36
|
+
'multipleOf',
|
|
37
|
+
'maximum',
|
|
38
|
+
'exclusiveMaximum',
|
|
39
|
+
'minimum',
|
|
40
|
+
'exclusiveMinimum',
|
|
41
|
+
'maxLength',
|
|
42
|
+
'minLength',
|
|
43
|
+
'pattern',
|
|
44
|
+
'maxItems',
|
|
45
|
+
'minItems',
|
|
46
|
+
'uniqueItems',
|
|
47
|
+
'maxProperties',
|
|
48
|
+
'minProperties',
|
|
49
|
+
'required',
|
|
50
|
+
];
|
|
51
|
+
// Has substantive schema keywords — not empty
|
|
52
|
+
if (s.allOf ||
|
|
53
|
+
s.oneOf ||
|
|
54
|
+
s.anyOf ||
|
|
55
|
+
s.items ||
|
|
56
|
+
s.$ref ||
|
|
57
|
+
'additionalProperties' in s ||
|
|
58
|
+
substantiveValidationKeywords.some((key) => key in s)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// Has properties with at least one defined property — not empty
|
|
62
|
+
if (typeof s.properties === 'object' && s.properties !== null && Object.keys(s.properties).length > 0) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Removes content entries that only have an empty schema (no example/examples)
|
|
69
|
+
* when other entries with actual examples exist. This prevents the UI from
|
|
70
|
+
* selecting a meaningless produces-based entry over one with a real example.
|
|
71
|
+
*/
|
|
72
|
+
function removeEmptySchemaOnlyContentEntries(content) {
|
|
73
|
+
const keys = Object.keys(content);
|
|
74
|
+
const hasEntryWithExample = keys.some((key) => {
|
|
75
|
+
const entry = content[key];
|
|
76
|
+
return entry?.example !== undefined || entry?.examples !== undefined;
|
|
77
|
+
});
|
|
78
|
+
if (!hasEntryWithExample) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
for (const key of keys) {
|
|
82
|
+
const entry = content[key];
|
|
83
|
+
if (!entry)
|
|
84
|
+
continue;
|
|
85
|
+
const hasExample = entry.example !== undefined || entry.examples !== undefined;
|
|
86
|
+
const hasOnlySchema = entry.schema !== undefined && !hasExample && Object.keys(entry).length === 1;
|
|
87
|
+
if (hasOnlySchema && isEmptySchema(entry.schema)) {
|
|
88
|
+
delete content[key];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
25
92
|
/** The allowed properties for an OpenAPI 3.x ExampleObject */
|
|
26
93
|
const EXAMPLE_OBJECT_PROPERTIES = new Set(['summary', 'description', 'value', 'externalValue']);
|
|
27
94
|
/**
|
|
@@ -263,6 +330,10 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
263
330
|
}
|
|
264
331
|
delete responseObj.examples;
|
|
265
332
|
}
|
|
333
|
+
// Clean up content entries that only have an empty schema when other entries have examples
|
|
334
|
+
if (responseObj.content && typeof responseObj.content === 'object') {
|
|
335
|
+
removeEmptySchemaOnlyContentEntries(responseObj.content);
|
|
336
|
+
}
|
|
266
337
|
// Transform headers if present
|
|
267
338
|
if (responseObj.headers && typeof responseObj.headers === 'object') {
|
|
268
339
|
responseObj.headers = Object.entries(responseObj.headers).reduce((acc, [headerName, header]) => {
|
|
@@ -373,6 +444,10 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
373
444
|
}
|
|
374
445
|
delete responseItem.examples;
|
|
375
446
|
}
|
|
447
|
+
// Clean up content entries that only have an empty schema when other entries have examples
|
|
448
|
+
if (responseItem.content && typeof responseItem.content === 'object') {
|
|
449
|
+
removeEmptySchemaOnlyContentEntries(responseItem.content);
|
|
450
|
+
}
|
|
376
451
|
}
|
|
377
452
|
}
|
|
378
453
|
}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"openapi 3.0",
|
|
21
21
|
"openapi 3.1"
|
|
22
22
|
],
|
|
23
|
-
"version": "0.2.
|
|
23
|
+
"version": "0.2.4",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=22"
|
|
26
26
|
},
|
|
@@ -71,11 +71,11 @@
|
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@scalar/openapi-types": "0.
|
|
74
|
+
"@scalar/openapi-types": "0.7.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"vite": "8.0.0",
|
|
78
|
-
"@scalar/types": "0.7.
|
|
78
|
+
"@scalar/types": "0.7.6"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|