@scalar/openapi-upgrader 0.4.2 → 0.4.4
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,17 @@
|
|
|
1
1
|
# @scalar/openapi-upgrader
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10559](https://github.com/scalar/scalar/pull/10559): Clean up Biome warnings in package code and tests. Handle rejected debounced callbacks and await streaming writes.
|
|
8
|
+
|
|
9
|
+
## 0.4.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#10501](https://github.com/scalar/scalar/pull/10501): Keep Swagger 2.0 named examples whose name contains a slash, such as `Coupons/Promos`. Only registered media types are treated as media-type keys, so one such name no longer drops every request body example.
|
|
14
|
+
|
|
3
15
|
## 0.4.2
|
|
4
16
|
|
|
5
17
|
## 0.4.1
|
|
@@ -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;
|
|
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;AAgMxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CAkczE"}
|
|
@@ -81,8 +81,9 @@ function removeEmptySchemaOnlyContentEntries(content) {
|
|
|
81
81
|
}
|
|
82
82
|
for (const key of keys) {
|
|
83
83
|
const entry = content[key];
|
|
84
|
-
if (!isObjectLike(entry))
|
|
84
|
+
if (!isObjectLike(entry)) {
|
|
85
85
|
continue;
|
|
86
|
+
}
|
|
86
87
|
const hasExample = entry.example !== undefined || entry.examples !== undefined;
|
|
87
88
|
const hasOnlySchema = entry.schema !== undefined && !hasExample && Object.keys(entry).length === 1;
|
|
88
89
|
if (hasOnlySchema && isEmptySchema(entry.schema)) {
|
|
@@ -120,14 +121,16 @@ function wrapAsExampleObject(value) {
|
|
|
120
121
|
/**
|
|
121
122
|
* True if the key looks like a MIME media type (e.g. application/json, text/plain).
|
|
122
123
|
* Used to distinguish media-type example keys from named example keys when migrating
|
|
123
|
-
* Swagger 2.0 examples to OpenAPI 3.0 content.
|
|
124
|
-
*
|
|
125
|
-
*
|
|
124
|
+
* Swagger 2.0 examples to OpenAPI 3.0 content. The type must be a registered top-level
|
|
125
|
+
* type (or `*`) and the subtype a single token, so named keys that contain a slash
|
|
126
|
+
* ("Error 404/Not Found", "Coupons/Promos") stay named examples. Matching is
|
|
127
|
+
* case-sensitive for undeclared keys so "Image/Before" stays a name. Explicit
|
|
128
|
+
* consumes/produces entries take precedence, including mixed-case or private types.
|
|
126
129
|
*/
|
|
127
|
-
const MEDIA_TYPE_KEY_PATTERN = /^[a-zA-Z0-9*+.-]
|
|
128
|
-
|
|
129
|
-
return MEDIA_TYPE_KEY_PATTERN.test(key);
|
|
130
|
-
}
|
|
130
|
+
const MEDIA_TYPE_KEY_PATTERN = /^(\*|application|audio|example|font|haptics|image|message|model|multipart|text|video)\/[a-zA-Z0-9*+.-]+$/;
|
|
131
|
+
const isMediaTypeKey = (key, declaredMediaTypes) => {
|
|
132
|
+
return declaredMediaTypes.includes(key) || MEDIA_TYPE_KEY_PATTERN.test(key);
|
|
133
|
+
};
|
|
131
134
|
/** Transforms x-example entries to OpenAPI 3.x examples format */
|
|
132
135
|
function transformXExampleToExamples(xExample) {
|
|
133
136
|
return Object.entries(xExample).reduce((acc, [key, value]) => {
|
|
@@ -308,7 +311,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
308
311
|
const defaultMediaType = produces[0] ?? DEFAULT_MEDIA_TYPE;
|
|
309
312
|
for (const [key, exampleValue] of Object.entries(responseObj.examples)) {
|
|
310
313
|
// Media-type keys (e.g. application/json) go to content[key]; named example keys go to content[defaultMediaType].examples[key].
|
|
311
|
-
if (isMediaTypeKey(key)) {
|
|
314
|
+
if (isMediaTypeKey(key, produces)) {
|
|
312
315
|
if (typeof responseObj.content[key] !== 'object') {
|
|
313
316
|
;
|
|
314
317
|
responseObj.content[key] = {};
|
|
@@ -427,7 +430,7 @@ export function upgradeFromTwoToThree(originalSpecification) {
|
|
|
427
430
|
const defaultMediaType = produces[0] ?? DEFAULT_MEDIA_TYPE;
|
|
428
431
|
for (const [key, exampleValue] of Object.entries(responseItem.examples)) {
|
|
429
432
|
// Media-type keys (e.g. application/json) go to content[key]; named example keys go to content[defaultMediaType].examples[key].
|
|
430
|
-
if (isMediaTypeKey(key)) {
|
|
433
|
+
if (isMediaTypeKey(key, operationItem.produces ?? produces)) {
|
|
431
434
|
if (typeof responseItem.content[key] !== 'object') {
|
|
432
435
|
responseItem.content[key] = {};
|
|
433
436
|
}
|
|
@@ -756,11 +759,15 @@ function migrateBodyParameter(bodyParameter, consumes) {
|
|
|
756
759
|
}
|
|
757
760
|
// Fallback: x-examples keyed by example name instead of media type
|
|
758
761
|
// e.g. x-examples: { Request: { email: "test@example.com" } }
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
762
|
+
// Decided per key, so a key that belongs to another media type never drops the named ones
|
|
763
|
+
else if (isNonEmptyObject(xExamples)) {
|
|
764
|
+
const namedExamples = Object.entries(xExamples).filter(([key]) => !isMediaTypeKey(key, consumes));
|
|
765
|
+
if (namedExamples.length) {
|
|
766
|
+
requestBodyObject.content[type].examples = namedExamples.reduce((acc, [key, exampleValue]) => {
|
|
767
|
+
acc[key] = wrapAsExampleObject(exampleValue);
|
|
768
|
+
return acc;
|
|
769
|
+
}, {});
|
|
770
|
+
}
|
|
764
771
|
}
|
|
765
772
|
// Handle x-example (singular) only when we did not set examples for this type
|
|
766
773
|
// (avoids having both example and examples on the same media type)
|
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.4",
|
|
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.
|
|
75
|
-
"@scalar/openapi-types": "0.9.
|
|
74
|
+
"@scalar/helpers": "0.16.3",
|
|
75
|
+
"@scalar/openapi-types": "0.9.8"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@scalar/types": "0.23.
|
|
78
|
+
"@scalar/types": "0.23.2",
|
|
79
79
|
"vite": "8.1.5"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|