@scalar/openapi-upgrader 0.4.4 → 0.4.5
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,5 +1,14 @@
|
|
|
1
1
|
# @scalar/openapi-upgrader
|
|
2
2
|
|
|
3
|
+
## 0.4.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10613](https://github.com/scalar/scalar/pull/10613): The 3.0 to 3.1 upgrade no longer skips the `default` entry of a Responses Object, which it mistook for the `default` keyword, so schemas in a default response are upgraded too.
|
|
8
|
+
- [#10613](https://github.com/scalar/scalar/pull/10613): Upgrade a `oneOf`/`anyOf` arm that only says `nullable: true` (optionally with annotations, including `default`) to `{ type: 'null' }`, so `oneOf: [{ nullable: true }, { $ref: X }]` becomes "X or null" in OpenAPI 3.1 instead of an arm that accepts any value.
|
|
9
|
+
|
|
10
|
+
Preserve nested extension payloads when upgrading nullable-only union arms.
|
|
11
|
+
|
|
3
12
|
## 0.4.4
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrade-from-three-to-three-one.d.ts","sourceRoot":"","sources":["../../src/3.0-to-3.1/upgrade-from-three-to-three-one.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"upgrade-from-three-to-three-one.d.ts","sourceRoot":"","sources":["../../src/3.0-to-3.1/upgrade-from-three-to-three-one.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAyHxD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;GAcxE"}
|
|
@@ -21,6 +21,16 @@ function isNamedSchemaMap(path) {
|
|
|
21
21
|
}
|
|
22
22
|
return NAMED_SCHEMA_MAP_SEGMENTS.has(last);
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Determine if `path[index]` is the `default` entry of a Responses Object.
|
|
26
|
+
*
|
|
27
|
+
* That `default` is a response, not the `default` keyword, so everything under it (its schemas
|
|
28
|
+
* included) still has to be upgraded. A schema property literally called `responses` does not
|
|
29
|
+
* count: there `default` is the keyword again.
|
|
30
|
+
*/
|
|
31
|
+
function isDefaultResponse(path, index) {
|
|
32
|
+
return path[index] === 'default' && path[index - 1] === 'responses' && !isNamedSchemaMap(path.slice(0, index - 1));
|
|
33
|
+
}
|
|
24
34
|
// Keywords whose value is arbitrary data rather than a schema. The upgrade rules only make
|
|
25
35
|
// sense for schema keywords, so nothing nested under these may be rewritten.
|
|
26
36
|
const DATA_KEYWORDS = new Set(['example', 'default', 'const', 'enum']);
|
|
@@ -38,7 +48,7 @@ function isInsideDataValue(path) {
|
|
|
38
48
|
for (const [index, segment] of path.entries()) {
|
|
39
49
|
// Only treat it as data when the keyword is a real keyword. Inside a named-schema map the
|
|
40
50
|
// same word (e.g. a property literally called `default`) is just a member name.
|
|
41
|
-
if (DATA_KEYWORDS.has(segment) && !isNamedSchemaMap(path.slice(0, index))) {
|
|
51
|
+
if (DATA_KEYWORDS.has(segment) && !isNamedSchemaMap(path.slice(0, index)) && !isDefaultResponse(path, index)) {
|
|
42
52
|
return true;
|
|
43
53
|
}
|
|
44
54
|
// The `value` of an Example Object (`examples/<name>/value`) holds arbitrary data too.
|
|
@@ -50,6 +60,45 @@ function isInsideDataValue(path) {
|
|
|
50
60
|
}
|
|
51
61
|
return false;
|
|
52
62
|
}
|
|
63
|
+
// Keywords that only describe a schema. An arm made of these and `nullable` constrains nothing else.
|
|
64
|
+
const ANNOTATION_KEYWORDS = new Set([
|
|
65
|
+
'title',
|
|
66
|
+
'description',
|
|
67
|
+
'deprecated',
|
|
68
|
+
'default',
|
|
69
|
+
'example',
|
|
70
|
+
'examples',
|
|
71
|
+
'externalDocs',
|
|
72
|
+
'readOnly',
|
|
73
|
+
'writeOnly',
|
|
74
|
+
]);
|
|
75
|
+
/**
|
|
76
|
+
* Determine if the node at `path` is one arm of a `oneOf` or `anyOf`.
|
|
77
|
+
*
|
|
78
|
+
* Extension payloads can contain objects that look like union arms too. Only interpret unions
|
|
79
|
+
* in schema context, keeping extension values opaque and allowing schema names prefixed by `x-`.
|
|
80
|
+
*/
|
|
81
|
+
function isUnionArm(path) {
|
|
82
|
+
if (!path || path.length < 2 || !isSchemaPath(path.slice(0, -2))) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const isInsideSchemaExtension = path.some((segment, index) => {
|
|
86
|
+
const parent = path.slice(0, index);
|
|
87
|
+
return segment.startsWith('x-') && isSchemaPath(parent) && !isNamedSchemaMap(parent);
|
|
88
|
+
});
|
|
89
|
+
if (isInsideSchemaExtension) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const keyword = path[path.length - 2];
|
|
93
|
+
const index = path[path.length - 1];
|
|
94
|
+
return (keyword === 'oneOf' || keyword === 'anyOf') && index !== undefined && /^\d+$/.test(index);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Determine if a schema carries `nullable: true` and nothing else but annotations and extensions.
|
|
98
|
+
*/
|
|
99
|
+
function isNullableOnly(schema) {
|
|
100
|
+
return Object.keys(schema).every((key) => key === 'nullable' || ANNOTATION_KEYWORDS.has(key) || key.startsWith('x-'));
|
|
101
|
+
}
|
|
53
102
|
/**
|
|
54
103
|
* Upgrade from OpenAPI 3.0.x to 3.1.1
|
|
55
104
|
*
|
|
@@ -93,6 +142,13 @@ const applyChangesToDocument = (schema, path) => {
|
|
|
93
142
|
const base = allOf.length === 1 ? allOf[0] : { allOf };
|
|
94
143
|
return { ...rest, anyOf: [base, { type: 'null' }] };
|
|
95
144
|
}
|
|
145
|
+
// A union arm that says nothing but `nullable: true` is how some 3.0 exporters spell "or null":
|
|
146
|
+
// `oneOf: [{ nullable: true }, { $ref: X }]`. Left alone, the arm reads as "any value" in 3.1 and
|
|
147
|
+
// swallows the real arm, so it becomes the `{ type: 'null' }` arm it was meant to be.
|
|
148
|
+
if (isUnionArm(path) && isNullableOnly(schema)) {
|
|
149
|
+
delete schema.nullable;
|
|
150
|
+
schema.type = 'null';
|
|
151
|
+
}
|
|
96
152
|
// Otherwise there is nothing for `nullable` to attach to, so leave the schema untouched.
|
|
97
153
|
}
|
|
98
154
|
// 2. Handle exclusiveMinimum and exclusiveMaximum
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"openapi 3.0",
|
|
21
21
|
"openapi 3.1"
|
|
22
22
|
],
|
|
23
|
-
"version": "0.4.
|
|
23
|
+
"version": "0.4.5",
|
|
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.16.
|
|
74
|
+
"@scalar/helpers": "0.16.4",
|
|
75
75
|
"@scalar/openapi-types": "0.9.8"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@scalar/types": "0.
|
|
78
|
+
"@scalar/types": "0.24.0",
|
|
79
79
|
"vite": "8.1.5"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|