@scalar/openapi-upgrader 0.3.0 → 0.3.1
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":"AACA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AA2LxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,
|
|
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":"AACA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AA2LxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CAkczE"}
|
|
@@ -185,6 +185,9 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
185
185
|
}
|
|
186
186
|
// Schemas
|
|
187
187
|
if (document.definitions) {
|
|
188
|
+
for (const schema of Object.values(document.definitions)) {
|
|
189
|
+
migrateSchemaNullability(schema);
|
|
190
|
+
}
|
|
188
191
|
document.components = Object.assign({}, document.components, {
|
|
189
192
|
schemas: document.definitions,
|
|
190
193
|
});
|
|
@@ -285,6 +288,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
285
288
|
const produces = document.produces ?? [DEFAULT_MEDIA_TYPE];
|
|
286
289
|
// Transform schema to content
|
|
287
290
|
if (responseObj.schema) {
|
|
291
|
+
migrateSchemaNullability(responseObj.schema);
|
|
288
292
|
if (typeof responseObj.content !== 'object') {
|
|
289
293
|
responseObj.content = {};
|
|
290
294
|
}
|
|
@@ -400,6 +404,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
400
404
|
}, {});
|
|
401
405
|
}
|
|
402
406
|
if (responseItem.schema) {
|
|
407
|
+
migrateSchemaNullability(responseItem.schema);
|
|
403
408
|
const produces = document.produces ?? operationItem.produces ?? [DEFAULT_MEDIA_TYPE];
|
|
404
409
|
if (typeof responseItem.content !== 'object') {
|
|
405
410
|
responseItem.content = {};
|
|
@@ -516,6 +521,34 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
516
521
|
delete document.produces;
|
|
517
522
|
return document;
|
|
518
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Swagger tooling uses x-nullable for the nullability keyword introduced in OpenAPI 3.0.
|
|
526
|
+
* Visit only subschemas so example/default values and custom extensions remain user data.
|
|
527
|
+
*/
|
|
528
|
+
const migrateSchemaNullability = (schema) => {
|
|
529
|
+
if (!isObjectLike(schema)) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (typeof schema['x-nullable'] === 'boolean') {
|
|
533
|
+
// False is already the default in OpenAPI 3.0 and needs no keyword in later versions.
|
|
534
|
+
if (schema['x-nullable']) {
|
|
535
|
+
schema.nullable = true;
|
|
536
|
+
}
|
|
537
|
+
delete schema['x-nullable'];
|
|
538
|
+
}
|
|
539
|
+
if (isObjectLike(schema.properties)) {
|
|
540
|
+
for (const property of Object.values(schema.properties)) {
|
|
541
|
+
migrateSchemaNullability(property);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
migrateSchemaNullability(schema.items);
|
|
545
|
+
migrateSchemaNullability(schema.additionalProperties);
|
|
546
|
+
if (Array.isArray(schema.allOf)) {
|
|
547
|
+
for (const member of schema.allOf) {
|
|
548
|
+
migrateSchemaNullability(member);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
};
|
|
519
552
|
function transformItemsObject(obj) {
|
|
520
553
|
const schemaProperties = [
|
|
521
554
|
'type',
|
|
@@ -534,14 +567,17 @@ function transformItemsObject(obj) {
|
|
|
534
567
|
'uniqueItems',
|
|
535
568
|
'enum',
|
|
536
569
|
'multipleOf',
|
|
570
|
+
'x-nullable',
|
|
537
571
|
];
|
|
538
|
-
|
|
572
|
+
const schema = schemaProperties.reduce((acc, property) => {
|
|
539
573
|
if (Object.hasOwn(obj, property)) {
|
|
540
574
|
acc[property] = obj[property];
|
|
541
575
|
delete obj[property];
|
|
542
576
|
}
|
|
543
577
|
return acc;
|
|
544
578
|
}, {});
|
|
579
|
+
migrateSchemaNullability(schema);
|
|
580
|
+
return schema;
|
|
545
581
|
}
|
|
546
582
|
function getParameterLocation(location) {
|
|
547
583
|
if (location === 'formData') {
|
|
@@ -683,6 +719,7 @@ function migrateBodyParameter(bodyParameter, consumes) {
|
|
|
683
719
|
delete bodyParameter.name;
|
|
684
720
|
delete bodyParameter.in;
|
|
685
721
|
const { schema, ...requestBody } = bodyParameter;
|
|
722
|
+
migrateSchemaNullability(schema);
|
|
686
723
|
const requestBodyObject = {
|
|
687
724
|
content: {},
|
|
688
725
|
...requestBody,
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"openapi 3.0",
|
|
21
21
|
"openapi 3.1"
|
|
22
22
|
],
|
|
23
|
-
"version": "0.3.
|
|
23
|
+
"version": "0.3.1",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=22"
|
|
26
26
|
},
|
|
@@ -71,11 +71,11 @@
|
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@scalar/helpers": "0.
|
|
74
|
+
"@scalar/helpers": "0.14.0",
|
|
75
75
|
"@scalar/openapi-types": "0.9.7"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@scalar/types": "0.
|
|
78
|
+
"@scalar/types": "0.22.0",
|
|
79
79
|
"vite": "8.1.5"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|