@scalar/openapi-upgrader 0.2.11 → 0.2.12
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,16 @@
|
|
|
1
1
|
# @scalar/openapi-upgrader
|
|
2
2
|
|
|
3
|
+
## 0.2.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#9758](https://github.com/scalar/scalar/pull/9758): fix: stop the 3.0 to 3.1 upgrade from mangling non-schema nodes
|
|
8
|
+
|
|
9
|
+
The upgrade applied its schema transforms to every object node, regardless of where it sat in the document. Three cases are now handled correctly:
|
|
10
|
+
- Members named `example` inside a map of named subschemas (`properties`, `patternProperties`, `$defs`, `definitions`, and `components/schemas`) are names, not the `example` keyword, so they are no longer rewritten into an `examples` array.
|
|
11
|
+
- Data held by the `example`, `default`, `const`, and `enum` keywords, and by an Example Object's `value`, is left untouched instead of being walked as if it were a schema (which turned `nullable: true` into a type array, collapsed `exclusiveMinimum`, renamed a nested `x-webhooks`, and so on).
|
|
12
|
+
- `x-webhooks` is only renamed to `webhooks` at the document root, not wherever a key happens to share that name.
|
|
13
|
+
|
|
3
14
|
## 0.2.11
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Scalar is an open-source API platform for teams who want beautiful developer int
|
|
|
20
20
|
|
|
21
21
|
- **[API References](https://scalar.com/products/api-references/getting-started)** — Interactive API documentation from OpenAPI and AsyncAPI specs.
|
|
22
22
|
- **[Developer Docs](https://scalar.com/products/docs/getting-started)** — Write in Markdown/MDX, generate API references, sync with two-way Git.
|
|
23
|
-
- **[SDK Generator](https://scalar.com/products/
|
|
23
|
+
- **[SDK Generator](https://scalar.com/products/sdk-generator/getting-started)** — Type-safe SDKs and CLIs in TypeScript, Python, Go, PHP, Java, and Ruby.
|
|
24
24
|
- **[API Client](https://scalar.com/products/api-client/getting-started)** — Open-source, offline-first Postman alternative built on OpenAPI.
|
|
25
25
|
|
|
26
26
|
20M+ monthly npm installs · 15,500+ GitHub stars · MIT licensed · [scalar.com](https://scalar.com)
|
|
@@ -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":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAgBxD,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAsBhE;
|
|
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":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAgBxD,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAsBhE;AA8DD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;GAcxE"}
|
|
@@ -30,6 +30,56 @@ export function isSchemaPath(path) {
|
|
|
30
30
|
}
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
|
+
// Segments whose value is a map of *named* subschemas. Keys inside these maps are
|
|
34
|
+
// arbitrary names (property names, definition names), never schema keywords.
|
|
35
|
+
const NAMED_SCHEMA_MAP_SEGMENTS = new Set(['properties', 'patternProperties', '$defs', 'definitions']);
|
|
36
|
+
/**
|
|
37
|
+
* Determine if the node at `path` is a map of named subschemas rather than a schema object.
|
|
38
|
+
*
|
|
39
|
+
* This matters because the 3.0 to 3.1 upgrade rewrites the `example` keyword into `examples`.
|
|
40
|
+
* A key called `example` (or `examples`) inside one of these maps is a member *name*, not the
|
|
41
|
+
* schema keyword, so it must be left untouched.
|
|
42
|
+
*/
|
|
43
|
+
function isNamedSchemaMap(path) {
|
|
44
|
+
const last = path?.[path.length - 1];
|
|
45
|
+
if (last === undefined) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// OpenAPI's named-schema map lives at components/schemas
|
|
49
|
+
if (last === 'schemas' && path?.[path.length - 2] === 'components') {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return NAMED_SCHEMA_MAP_SEGMENTS.has(last);
|
|
53
|
+
}
|
|
54
|
+
// Keywords whose value is arbitrary data rather than a schema. The upgrade rules only make
|
|
55
|
+
// sense for schema keywords, so nothing nested under these may be rewritten.
|
|
56
|
+
const DATA_KEYWORDS = new Set(['example', 'default', 'const', 'enum']);
|
|
57
|
+
/**
|
|
58
|
+
* Determine if the node at `path` lives inside a data value rather than a schema.
|
|
59
|
+
*
|
|
60
|
+
* The traversal visits every object node, but a value held by keywords like `example` or
|
|
61
|
+
* `default` is user data, not a schema. Applying the schema transforms to it would mangle it
|
|
62
|
+
* (turning `nullable: true` into a type array, renaming a nested `x-webhooks`, and so on).
|
|
63
|
+
*/
|
|
64
|
+
function isInsideDataValue(path) {
|
|
65
|
+
if (!path) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
for (const [index, segment] of path.entries()) {
|
|
69
|
+
// Only treat it as data when the keyword is a real keyword. Inside a named-schema map the
|
|
70
|
+
// same word (e.g. a property literally called `default`) is just a member name.
|
|
71
|
+
if (DATA_KEYWORDS.has(segment) && !isNamedSchemaMap(path.slice(0, index))) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
// The `value` of an Example Object (`examples/<name>/value`) holds arbitrary data too.
|
|
75
|
+
// Require a real examples map two segments up so a property named `value` inside a schema
|
|
76
|
+
// named `examples` is not mistaken for it.
|
|
77
|
+
if (segment === 'value' && path[index - 2] === 'examples' && !isNamedSchemaMap(path.slice(0, index - 2))) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
33
83
|
/**
|
|
34
84
|
* Upgrade from OpenAPI 3.0.x to 3.1.1
|
|
35
85
|
*
|
|
@@ -47,6 +97,11 @@ export function upgradeFromThreeToThreeOne(originalContent) {
|
|
|
47
97
|
return content;
|
|
48
98
|
}
|
|
49
99
|
const applyChangesToDocument = (schema, path) => {
|
|
100
|
+
// 0. Bail out inside data values (example, default, const, enum). These hold user data, not a
|
|
101
|
+
// schema, so none of the schema transforms below apply and running them would corrupt the data.
|
|
102
|
+
if (isInsideDataValue(path)) {
|
|
103
|
+
return schema;
|
|
104
|
+
}
|
|
50
105
|
// 1. Handle nullable types
|
|
51
106
|
if (schema.type !== undefined && schema.nullable === true) {
|
|
52
107
|
schema.type = [schema.type, 'null'];
|
|
@@ -70,17 +125,17 @@ const applyChangesToDocument = (schema, path) => {
|
|
|
70
125
|
// 3. Handle examples
|
|
71
126
|
// Skip conversion if we're already inside an examples map to avoid double nesting
|
|
72
127
|
// Check if 'examples' appears as an exact path segment (not just a substring)
|
|
73
|
-
// BUT exclude cases where 'examples' is just a schema property
|
|
128
|
+
// BUT exclude cases where 'examples' is just a named-schema-map member (e.g. a property named 'examples')
|
|
74
129
|
const isInsideExamplesMap = path?.some((segment, index) => {
|
|
75
|
-
// Only consider it an examples map if 'examples' is not a schema property name
|
|
76
130
|
if (segment === 'examples' && index > 0) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return parent !== 'properties';
|
|
131
|
+
// If the parent node is a named-schema map, 'examples' is a member name, not an examples map
|
|
132
|
+
return !isNamedSchemaMap(path.slice(0, index));
|
|
80
133
|
}
|
|
81
134
|
return false;
|
|
82
135
|
});
|
|
83
|
-
|
|
136
|
+
// If the current node is itself a map of named subschemas, a key called 'example' is a
|
|
137
|
+
// member name (property, $defs entry, components/schemas entry) and not the schema keyword.
|
|
138
|
+
if (schema.example !== undefined && !isInsideExamplesMap && !isNamedSchemaMap(path)) {
|
|
84
139
|
if (isSchemaPath(path)) {
|
|
85
140
|
schema.examples = [schema.example];
|
|
86
141
|
}
|
|
@@ -146,7 +201,9 @@ const applyChangesToDocument = (schema, path) => {
|
|
|
146
201
|
}
|
|
147
202
|
}
|
|
148
203
|
// 7. Handle x-webhooks
|
|
149
|
-
|
|
204
|
+
// `x-webhooks` is a document-root extension, so only rename it there. Anywhere else (a schema
|
|
205
|
+
// property, an example) a key named `x-webhooks` is unrelated and must be left alone.
|
|
206
|
+
if (schema['x-webhooks'] !== undefined && (path === undefined || path.length === 0)) {
|
|
150
207
|
schema.webhooks = schema['x-webhooks'];
|
|
151
208
|
delete schema['x-webhooks'];
|
|
152
209
|
}
|
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.12",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=22"
|
|
26
26
|
},
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@scalar/openapi-types": "0.9.
|
|
74
|
+
"@scalar/openapi-types": "0.9.4"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"vite": "8.0.0",
|
|
78
|
-
"@scalar/
|
|
79
|
-
"@scalar/
|
|
78
|
+
"@scalar/types": "0.17.0",
|
|
79
|
+
"@scalar/helpers": "0.9.2"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|