@scalar/openapi-upgrader 0.2.1 → 0.2.2
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
|
@@ -604,13 +604,10 @@ function migrateBodyParameter(bodyParameter, consumes) {
|
|
|
604
604
|
requestBodyObject.content[type] = {
|
|
605
605
|
schema: schema,
|
|
606
606
|
};
|
|
607
|
-
// Handle x-
|
|
608
|
-
// Transforms to OpenAPI 3.x `
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
// Handle x-examples (plural) - Redocly extension for Swagger 2.0
|
|
613
|
-
// Transforms to OpenAPI 3.x `examples` field (named examples with summary/value)
|
|
607
|
+
// Handle x-examples (plural) first - Redocly extension for Swagger 2.0
|
|
608
|
+
// Transforms to OpenAPI 3.x `examples` field (named examples with summary/value).
|
|
609
|
+
// When both x-example and x-examples exist, we prefer x-examples so each media type
|
|
610
|
+
// has only one of `example` or `examples` (OpenAPI 3 does not use both on the same type).
|
|
614
611
|
if (isNonEmptyObject(xExamples) && type in xExamples) {
|
|
615
612
|
const examples = xExamples[type];
|
|
616
613
|
// Check if examples is already in proper OpenAPI 3.x format (object with entries that are valid ExampleObjects)
|
|
@@ -635,17 +632,15 @@ function migrateBodyParameter(bodyParameter, consumes) {
|
|
|
635
632
|
// Fallback: x-examples keyed by example name instead of media type
|
|
636
633
|
// e.g. x-examples: { Request: { email: "test@example.com" } }
|
|
637
634
|
else if (isNonEmptyObject(xExamples) && !Object.keys(xExamples).some(isMediaTypeKey)) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
};
|
|
648
|
-
}
|
|
635
|
+
requestBodyObject.content[type].examples = Object.entries(xExamples).reduce((acc, [key, exampleValue]) => {
|
|
636
|
+
acc[key] = wrapAsExampleObject(exampleValue);
|
|
637
|
+
return acc;
|
|
638
|
+
}, {});
|
|
639
|
+
}
|
|
640
|
+
// Handle x-example (singular) only when we did not set examples for this type
|
|
641
|
+
// (avoids having both example and examples on the same media type)
|
|
642
|
+
if (!requestBodyObject.content[type].examples && isNonEmptyObject(xExample) && type in xExample) {
|
|
643
|
+
requestBodyObject.content[type].example = xExample[type];
|
|
649
644
|
}
|
|
650
645
|
}
|
|
651
646
|
}
|