@scalar/openapi-upgrader 0.2.15 → 0.2.17
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 +20 -0
- package/dist/2.0-to-3.0/upgrade-from-two-to-three.d.ts.map +1 -1
- package/dist/2.0-to-3.0/upgrade-from-two-to-three.js +10 -14
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.d.ts +0 -2
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.d.ts.map +1 -1
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +17 -79
- package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +1 -1
- package/dist/helpers/traverse.d.ts.map +1 -1
- package/dist/helpers/traverse.js +2 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @scalar/openapi-upgrader
|
|
2
2
|
|
|
3
|
+
## 0.2.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10236](https://github.com/scalar/scalar/pull/10236): Omit exclusive bounds without a minimum or maximum when upgrading OpenAPI 3.0 descriptions.
|
|
8
|
+
- [#10236](https://github.com/scalar/scalar/pull/10236): Avoid undefined or inferred media types for base64-encoded data when upgrading OpenAPI 3.0 descriptions.
|
|
9
|
+
- [#10236](https://github.com/scalar/scalar/pull/10236): Fix format conversion for nullable strings when upgrading OpenAPI 3.0 descriptions.
|
|
10
|
+
- [#10236](https://github.com/scalar/scalar/pull/10236): Omit JSON type constraints for raw binary schemas and preserve media metadata when upgrading OpenAPI 3.0 descriptions.
|
|
11
|
+
|
|
12
|
+
## 0.2.16
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#9666](https://github.com/scalar/scalar/pull/9666): Only normalize OpenAPI Reference Objects during bundling, never Schema Objects. `normalizeRefs` used to strip every sibling except `$ref` on any node outside `components/schemas`, which also hit inline schemas. In JSON Schema 2020-12 a `$ref` may legally carry sibling keywords — for example a `$defs`/`$dynamicAnchor` binding that specializes a generic template like `Paginated<T>` — and such schemas appear inline anywhere a schema is allowed (a response's `content.<media>.schema`, an `allOf` branch, …). Dropping those siblings discarded the binding, leaving `$dynamicRef` to resolve to the template's empty fallback and rendering an empty array (for example the `data` array of `GET /planets` in the Scalar Galaxy). Reference Objects are still normalized as before. A new `@scalar/helpers/openapi/is-schema-path` helper detects schema positions.
|
|
17
|
+
- [#10140](https://github.com/scalar/scalar/pull/10140): Replace redundant type assertions with compiler-checked annotations, typed accumulators, and existing guards across helpers, API conversion, request handling, and schema rendering.
|
|
18
|
+
|
|
19
|
+
Narrow DOM elements and caught errors before accessing their properties. Correct header lookup to include missing values and handle them during PowerShell snippet generation.
|
|
20
|
+
|
|
21
|
+
Validate release-note provider responses, represent unresolved references and absent groups in helper return types, and require narrowing merged object values. Preserve AsyncAPI broker credentials separately from HTTP authentication schemes.
|
|
22
|
+
|
|
3
23
|
## 0.2.15
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -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":"
|
|
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,0CA4bzE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isObjectLike } from '@scalar/helpers/object/is-object';
|
|
1
2
|
import { traverse } from '../helpers/traverse.js';
|
|
2
3
|
const DEFAULT_MEDIA_TYPE = 'application/json';
|
|
3
4
|
/** Extracts and removes x-example and x-examples extensions from an object */
|
|
@@ -24,7 +25,7 @@ function isNamedExamplesCollection(value) {
|
|
|
24
25
|
}
|
|
25
26
|
/** Checks if a schema is empty (no meaningful properties defined) */
|
|
26
27
|
function isEmptySchema(schema) {
|
|
27
|
-
if (
|
|
28
|
+
if (!isObjectLike(schema)) {
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
const s = schema;
|
|
@@ -73,14 +74,14 @@ function removeEmptySchemaOnlyContentEntries(content) {
|
|
|
73
74
|
const keys = Object.keys(content);
|
|
74
75
|
const hasEntryWithExample = keys.some((key) => {
|
|
75
76
|
const entry = content[key];
|
|
76
|
-
return entry
|
|
77
|
+
return isObjectLike(entry) && (entry.example !== undefined || entry.examples !== undefined);
|
|
77
78
|
});
|
|
78
79
|
if (!hasEntryWithExample) {
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
for (const key of keys) {
|
|
82
83
|
const entry = content[key];
|
|
83
|
-
if (!entry)
|
|
84
|
+
if (!isObjectLike(entry))
|
|
84
85
|
continue;
|
|
85
86
|
const hasExample = entry.example !== undefined || entry.examples !== undefined;
|
|
86
87
|
const hasOnlySchema = entry.schema !== undefined && !hasExample && Object.keys(entry).length === 1;
|
|
@@ -213,7 +214,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
213
214
|
if (!schemaName) {
|
|
214
215
|
return schema;
|
|
215
216
|
}
|
|
216
|
-
const param = document.parameters &&
|
|
217
|
+
const param = isObjectLike(document.parameters) && schemaName in document.parameters
|
|
217
218
|
? document.parameters[schemaName]
|
|
218
219
|
: undefined;
|
|
219
220
|
if (param && typeof param === 'object' && 'in' in param && (param.in === 'body' || param.in === 'formData')) {
|
|
@@ -228,9 +229,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
228
229
|
document.components ??= {};
|
|
229
230
|
const params = {};
|
|
230
231
|
const bodyParams = {};
|
|
231
|
-
const parameters = document.parameters
|
|
232
|
-
? document.parameters
|
|
233
|
-
: {};
|
|
232
|
+
const parameters = isObjectLike(document.parameters) ? document.parameters : {};
|
|
234
233
|
for (const [name, param] of Object.entries(parameters)) {
|
|
235
234
|
if (param && typeof param === 'object') {
|
|
236
235
|
// Handle reference objects
|
|
@@ -275,7 +274,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
275
274
|
const migratedResponses = {};
|
|
276
275
|
const responses = document.responses;
|
|
277
276
|
for (const [name, response] of Object.entries(responses)) {
|
|
278
|
-
if (response
|
|
277
|
+
if (isObjectLike(response)) {
|
|
279
278
|
// Handle reference objects
|
|
280
279
|
if ('$ref' in response) {
|
|
281
280
|
migratedResponses[name] = response;
|
|
@@ -335,7 +334,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
335
334
|
removeEmptySchemaOnlyContentEntries(responseObj.content);
|
|
336
335
|
}
|
|
337
336
|
// Transform headers if present
|
|
338
|
-
if (responseObj.headers
|
|
337
|
+
if (isObjectLike(responseObj.headers)) {
|
|
339
338
|
responseObj.headers = Object.entries(responseObj.headers).reduce((acc, [headerName, header]) => {
|
|
340
339
|
if (header && typeof header === 'object') {
|
|
341
340
|
return {
|
|
@@ -360,9 +359,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
360
359
|
if (typeof document.paths === 'object') {
|
|
361
360
|
for (const path in document.paths) {
|
|
362
361
|
if (Object.hasOwn(document.paths, path)) {
|
|
363
|
-
const pathItem = document.paths &&
|
|
364
|
-
? document.paths[path]
|
|
365
|
-
: undefined;
|
|
362
|
+
const pathItem = isObjectLike(document.paths) && path in document.paths ? document.paths[path] : undefined;
|
|
366
363
|
if (!pathItem || typeof pathItem !== 'object') {
|
|
367
364
|
continue;
|
|
368
365
|
}
|
|
@@ -657,8 +654,7 @@ function getParameterSerializationStyle(parameter) {
|
|
|
657
654
|
return {};
|
|
658
655
|
}
|
|
659
656
|
const collectionFormat = parameter.collectionFormat ?? 'csv';
|
|
660
|
-
if (parameter.in in serializationStyles &&
|
|
661
|
-
collectionFormat in serializationStyles[parameter.in]) {
|
|
657
|
+
if (parameter.in in serializationStyles && collectionFormat in serializationStyles[parameter.in]) {
|
|
662
658
|
return serializationStyles[parameter.in][collectionFormat];
|
|
663
659
|
}
|
|
664
660
|
return {};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
2
2
|
import type { UnknownObject } from '@scalar/types/utils';
|
|
3
|
-
/** Determine if the current path is within a schema - optimized version */
|
|
4
|
-
export declare function isSchemaPath(path: string[] | undefined): boolean;
|
|
5
3
|
/**
|
|
6
4
|
* Upgrade from OpenAPI 3.0.x to 3.1.1
|
|
7
5
|
*
|
|
@@ -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":"
|
|
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;AAgExD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;GAcxE"}
|
|
@@ -1,35 +1,5 @@
|
|
|
1
|
+
import { isSchemaPath } from '@scalar/helpers/openapi/is-schema-path';
|
|
1
2
|
import { traverse } from '../helpers/traverse.js';
|
|
2
|
-
// Create Sets for faster schema path lookups
|
|
3
|
-
const SCHEMA_SEGMENTS = new Set([
|
|
4
|
-
'properties',
|
|
5
|
-
'items',
|
|
6
|
-
'allOf',
|
|
7
|
-
'anyOf',
|
|
8
|
-
'oneOf',
|
|
9
|
-
'not',
|
|
10
|
-
'additionalProperties',
|
|
11
|
-
'schema',
|
|
12
|
-
]);
|
|
13
|
-
/** Determine if the current path is within a schema - optimized version */
|
|
14
|
-
export function isSchemaPath(path) {
|
|
15
|
-
// Early return if path is undefined
|
|
16
|
-
if (!path) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
// Check for schema segments first (most common case)
|
|
20
|
-
if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
// Check for schema suffix
|
|
24
|
-
if (path.some((segment) => segment.endsWith('Schema'))) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
// Check for components/schemas path
|
|
28
|
-
if (path.length >= 2 && path[0] === 'components' && path[1] === 'schemas') {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
3
|
// Segments whose value is a map of *named* subschemas. Keys inside these maps are
|
|
34
4
|
// arbitrary names (property names, definition names), never schema keywords.
|
|
35
5
|
const NAMED_SCHEMA_MAP_SEGMENTS = new Set(['properties', 'patternProperties', '$defs', 'definitions']);
|
|
@@ -126,18 +96,18 @@ const applyChangesToDocument = (schema, path) => {
|
|
|
126
96
|
// Otherwise there is nothing for `nullable` to attach to, so leave the schema untouched.
|
|
127
97
|
}
|
|
128
98
|
// 2. Handle exclusiveMinimum and exclusiveMaximum
|
|
129
|
-
if (schema.exclusiveMinimum === true) {
|
|
99
|
+
if (schema.exclusiveMinimum === true && schema.minimum !== undefined) {
|
|
130
100
|
schema.exclusiveMinimum = schema.minimum;
|
|
131
101
|
delete schema.minimum;
|
|
132
102
|
}
|
|
133
|
-
else if (schema.exclusiveMinimum ===
|
|
103
|
+
else if (typeof schema.exclusiveMinimum === 'boolean') {
|
|
134
104
|
delete schema.exclusiveMinimum;
|
|
135
105
|
}
|
|
136
|
-
if (schema.exclusiveMaximum === true) {
|
|
106
|
+
if (schema.exclusiveMaximum === true && schema.maximum !== undefined) {
|
|
137
107
|
schema.exclusiveMaximum = schema.maximum;
|
|
138
108
|
delete schema.maximum;
|
|
139
109
|
}
|
|
140
|
-
else if (schema.exclusiveMaximum ===
|
|
110
|
+
else if (typeof schema.exclusiveMaximum === 'boolean') {
|
|
141
111
|
delete schema.exclusiveMaximum;
|
|
142
112
|
}
|
|
143
113
|
// 3. Handle examples
|
|
@@ -166,59 +136,27 @@ const applyChangesToDocument = (schema, path) => {
|
|
|
166
136
|
}
|
|
167
137
|
delete schema.example;
|
|
168
138
|
}
|
|
169
|
-
// 4. Handle
|
|
170
|
-
if (schema.type === 'object' && schema.properties !== undefined) {
|
|
171
|
-
const parentPath = path?.slice(0, -1);
|
|
172
|
-
const isMultipart = parentPath?.some((segment, index) => {
|
|
173
|
-
return segment === 'content' && path?.[index + 1] === 'multipart/form-data';
|
|
174
|
-
});
|
|
175
|
-
if (isMultipart && schema.properties !== null) {
|
|
176
|
-
for (const value of Object.values(schema.properties)) {
|
|
177
|
-
if (typeof value === 'object' &&
|
|
178
|
-
value !== null &&
|
|
179
|
-
'type' in value &&
|
|
180
|
-
'format' in value &&
|
|
181
|
-
value.type === 'string' &&
|
|
182
|
-
value.format === 'binary') {
|
|
183
|
-
value.contentMediaType = 'application/octet-stream';
|
|
184
|
-
delete value.format;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
// 5. Handle binary file uploads
|
|
190
|
-
if (path?.includes('content') && path?.includes('application/octet-stream')) {
|
|
191
|
-
return {};
|
|
192
|
-
}
|
|
193
|
-
// 6. Handle older formats
|
|
139
|
+
// 4. Handle older formats
|
|
194
140
|
const { format: _, ...rest } = schema;
|
|
195
|
-
if (schema.type === 'string') {
|
|
141
|
+
if (schema.type === 'string' || (Array.isArray(schema.type) && schema.type.includes('string'))) {
|
|
196
142
|
if (schema.format === 'binary') {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (schema.format === 'base64') {
|
|
204
|
-
return {
|
|
205
|
-
...rest,
|
|
206
|
-
type: 'string',
|
|
207
|
-
contentEncoding: 'base64',
|
|
208
|
-
};
|
|
143
|
+
// Raw binary is outside JSON Schema's types, including nullable type unions.
|
|
144
|
+
const { type: _type, ...binarySchema } = rest;
|
|
145
|
+
const hasMediaType = path?.at(-1) === 'schema' && path.at(-3) === 'content';
|
|
146
|
+
// A whole-body schema already has its media type. Reusable schemas and multipart
|
|
147
|
+
// properties need a fallback, while explicit Encoding Objects remain authoritative.
|
|
148
|
+
return hasMediaType ? binarySchema : { contentMediaType: 'application/octet-stream', ...binarySchema };
|
|
209
149
|
}
|
|
210
|
-
if (schema.format === 'byte') {
|
|
211
|
-
|
|
212
|
-
|
|
150
|
+
if (schema.format === 'base64' || schema.format === 'byte') {
|
|
151
|
+
// The surrounding media type describes the container, not necessarily the
|
|
152
|
+
// encoded bytes. Preserve an explicit contentMediaType without guessing one.
|
|
213
153
|
return {
|
|
214
154
|
...rest,
|
|
215
|
-
type: 'string',
|
|
216
155
|
contentEncoding: 'base64',
|
|
217
|
-
contentMediaType,
|
|
218
156
|
};
|
|
219
157
|
}
|
|
220
158
|
}
|
|
221
|
-
//
|
|
159
|
+
// 5. Handle x-webhooks
|
|
222
160
|
// `x-webhooks` is a document-root extension, so only rename it there. Anywhere else (a schema
|
|
223
161
|
// property, an example) a key named `x-webhooks` is unrelated and must be left alone.
|
|
224
162
|
if (schema['x-webhooks'] !== undefined && (path === undefined || path.length === 0)) {
|
|
@@ -55,7 +55,7 @@ function migrateTagGroups(document) {
|
|
|
55
55
|
// Update existing tags with kind property based on group name
|
|
56
56
|
if (Array.isArray(document.tags)) {
|
|
57
57
|
for (const tag of document.tags) {
|
|
58
|
-
if (typeof tag === 'object' && tag !== null && 'name' in tag) {
|
|
58
|
+
if (typeof tag === 'object' && tag !== null && 'name' in tag && typeof tag.name === 'string') {
|
|
59
59
|
const groupName = tagGroupMap.get(tag.name);
|
|
60
60
|
if (groupName) {
|
|
61
61
|
// Map group names to kind values
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/helpers/traverse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/helpers/traverse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD;;GAEG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,aAAa,EACrE,IAAI,GAAE,MAAM,EAAO,iBA6BpB"}
|
package/dist/helpers/traverse.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isObjectLike } from '@scalar/helpers/object/is-object';
|
|
1
2
|
/**
|
|
2
3
|
* Recursively traverses the content and applies the transform function to each node.
|
|
3
4
|
*/
|
|
@@ -14,7 +15,7 @@ export function traverse(content, transform, path = []) {
|
|
|
14
15
|
});
|
|
15
16
|
continue;
|
|
16
17
|
}
|
|
17
|
-
if (
|
|
18
|
+
if (isObjectLike(value)) {
|
|
18
19
|
result[key] = traverse(value, transform, currentPath);
|
|
19
20
|
continue;
|
|
20
21
|
}
|
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.17",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=22"
|
|
26
26
|
},
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
},
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@scalar/
|
|
74
|
+
"@scalar/helpers": "0.12.0",
|
|
75
|
+
"@scalar/openapi-types": "0.9.6"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"@scalar/types": "0.18.2"
|
|
78
|
+
"@scalar/types": "0.20.0",
|
|
79
|
+
"vite": "8.1.5"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|