@scalar/openapi-upgrader 0.2.13 → 0.2.16
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 +23 -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 +38 -17
- 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 +1 -31
- 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 +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @scalar/openapi-upgrader
|
|
2
2
|
|
|
3
|
+
## 0.2.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
- [#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.
|
|
9
|
+
|
|
10
|
+
Narrow DOM elements and caught errors before accessing their properties. Correct header lookup to include missing values and handle them during PowerShell snippet generation.
|
|
11
|
+
|
|
12
|
+
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.
|
|
13
|
+
|
|
14
|
+
## 0.2.15
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#9941](https://github.com/scalar/scalar/pull/9941): Republish every package through npm trusted publishing. No functional changes.
|
|
19
|
+
|
|
20
|
+
## 0.2.14
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [#9910](https://github.com/scalar/scalar/pull/9910): Keep the full schema of a Swagger 2.0 `formData` parameter when upgrading to OpenAPI 3.0. The request body property was rebuilt from `type`, `description` and `format` only, so a parameter with `type: 'array'` lost its `items` and consumers of the upgraded document saw an array of unknown values. `items`, `enum`, `default` and the other validation keywords now survive, and the array `collectionFormat` is carried over as an OpenAPI 3.0 `encoding` entry (`style`/`explode`) instead of being dropped.
|
|
25
|
+
|
|
3
26
|
## 0.2.13
|
|
4
27
|
|
|
5
28
|
### 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,12 +654,28 @@ 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 {};
|
|
665
661
|
}
|
|
662
|
+
/**
|
|
663
|
+
* Translate the Swagger 2.0 `collectionFormat` of a formData array parameter into an OpenAPI 3.0
|
|
664
|
+
* encoding entry. Form bodies serialize arrays with the same styles as query parameters, so the
|
|
665
|
+
* query serialization mapping is reused. Returns undefined when there is nothing to preserve, for
|
|
666
|
+
* example a non-array parameter, one without a `collectionFormat`, or `tsv` which has no OpenAPI
|
|
667
|
+
* 3.0 equivalent.
|
|
668
|
+
*/
|
|
669
|
+
function getFormDataEncoding(parameter) {
|
|
670
|
+
if (parameter.type !== 'array' || typeof parameter.collectionFormat !== 'string') {
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
const encoding = querySerialization[parameter.collectionFormat];
|
|
674
|
+
if (!encoding || Object.keys(encoding).length === 0) {
|
|
675
|
+
return undefined;
|
|
676
|
+
}
|
|
677
|
+
return encoding;
|
|
678
|
+
}
|
|
666
679
|
function migrateBodyParameter(bodyParameter, consumes) {
|
|
667
680
|
// Extract x-example and x-examples before deleting other properties
|
|
668
681
|
// @see https://redocly.com/docs-legacy/api-reference-docs/specification-extensions/x-examples
|
|
@@ -742,10 +755,18 @@ function migrateFormDataParameter(parameters, consumes = ['multipart/form-data']
|
|
|
742
755
|
for (const param of parameters) {
|
|
743
756
|
if (param.name && formContent.schema.properties) {
|
|
744
757
|
formContent.schema.properties[param.name] = {
|
|
745
|
-
|
|
746
|
-
description
|
|
747
|
-
|
|
758
|
+
...transformItemsObject(structuredClone(param)),
|
|
759
|
+
// Only carry the description over when it exists, so a parameter without one does not
|
|
760
|
+
// end up with an explicit `description: undefined` on its schema.
|
|
761
|
+
...(param.description !== undefined ? { description: param.description } : {}),
|
|
748
762
|
};
|
|
763
|
+
// Preserve the array serialization hint (Swagger 2.0 `collectionFormat`) as an
|
|
764
|
+
// OpenAPI 3.0 encoding entry on the media type, so it is not silently dropped.
|
|
765
|
+
const encoding = getFormDataEncoding(param);
|
|
766
|
+
if (encoding) {
|
|
767
|
+
formContent.encoding ??= {};
|
|
768
|
+
formContent.encoding[param.name] = encoding;
|
|
769
|
+
}
|
|
749
770
|
// Add to required array if param is required
|
|
750
771
|
if (param.required && Array.isArray(formContent.schema.required)) {
|
|
751
772
|
formContent.schema.required.push(param.name);
|
|
@@ -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']);
|
|
@@ -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.16",
|
|
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.6",
|
|
75
|
+
"@scalar/helpers": "0.12.0"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
78
|
"vite": "8.1.5",
|
|
78
|
-
"@scalar/
|
|
79
|
-
"@scalar/types": "0.17.1"
|
|
79
|
+
"@scalar/types": "0.20.0"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|