oas 20.8.6 → 20.8.8
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.
|
@@ -609,7 +609,7 @@ function toJSONSchema(data, opts) {
|
|
|
609
609
|
Object.keys(schema.properties).forEach(function (prop) {
|
|
610
610
|
if (Array.isArray(schema.properties[prop]) ||
|
|
611
611
|
(typeof schema.properties[prop] === 'object' && schema.properties[prop] !== null)) {
|
|
612
|
-
|
|
612
|
+
var newPropSchema = toJSONSchema(schema.properties[prop], {
|
|
613
613
|
addEnumsToDescriptions: addEnumsToDescriptions,
|
|
614
614
|
currentLocation: "".concat(currentLocation, "/").concat(encodePointer(prop)),
|
|
615
615
|
globalDefaults: globalDefaults,
|
|
@@ -620,10 +620,19 @@ function toJSONSchema(data, opts) {
|
|
|
620
620
|
transformer: transformer,
|
|
621
621
|
});
|
|
622
622
|
// If this property is read or write only then we should fully hide it from its parent schema.
|
|
623
|
-
if (hideReadOnlyProperties || hideWriteOnlyProperties) {
|
|
624
|
-
if
|
|
623
|
+
if ((hideReadOnlyProperties || hideWriteOnlyProperties) && !Object.keys(newPropSchema).length) {
|
|
624
|
+
// We should only delete this schema if it wasn't already empty though. We do this
|
|
625
|
+
// because we (un)fortunately have handling in our API Explorer form system for
|
|
626
|
+
// schemas that are devoid of any `type` declaration.
|
|
627
|
+
if (Object.keys(schema.properties[prop]).length > 0) {
|
|
625
628
|
delete schema.properties[prop];
|
|
626
629
|
}
|
|
630
|
+
else {
|
|
631
|
+
schema.properties[prop] = newPropSchema;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
schema.properties[prop] = newPropSchema;
|
|
627
636
|
}
|
|
628
637
|
}
|
|
629
638
|
});
|
|
@@ -704,6 +713,13 @@ function toJSONSchema(data, opts) {
|
|
|
704
713
|
}
|
|
705
714
|
// Only add a default value if we actually have one.
|
|
706
715
|
if ('default' in schema && typeof schema.default !== 'undefined') {
|
|
716
|
+
// If it's an enum and not the response schema, add the default to the description.
|
|
717
|
+
// If there's an existing description, trim trailing new lines so it doesn't look ugly.
|
|
718
|
+
if ('enum' in schema && !addEnumsToDescriptions) {
|
|
719
|
+
schema.description = schema.description
|
|
720
|
+
? "".concat(schema.description.replace(/\n$/, ''), "\n\nDefault: ").concat(schema.default)
|
|
721
|
+
: "Default: ".concat(schema.default);
|
|
722
|
+
}
|
|
707
723
|
if (('allowEmptyValue' in schema && schema.allowEmptyValue && schema.default === '') || schema.default !== '') {
|
|
708
724
|
// If we have `allowEmptyValue` present, and the default is actually an empty string, let it
|
|
709
725
|
// through as it's allowed.
|
package/package.json
CHANGED
|
@@ -673,7 +673,7 @@ export default function toJSONSchema(
|
|
|
673
673
|
Array.isArray(schema.properties[prop]) ||
|
|
674
674
|
(typeof schema.properties[prop] === 'object' && schema.properties[prop] !== null)
|
|
675
675
|
) {
|
|
676
|
-
|
|
676
|
+
const newPropSchema = toJSONSchema(schema.properties[prop] as RMOAS.SchemaObject, {
|
|
677
677
|
addEnumsToDescriptions,
|
|
678
678
|
currentLocation: `${currentLocation}/${encodePointer(prop)}`,
|
|
679
679
|
globalDefaults,
|
|
@@ -685,10 +685,17 @@ export default function toJSONSchema(
|
|
|
685
685
|
});
|
|
686
686
|
|
|
687
687
|
// If this property is read or write only then we should fully hide it from its parent schema.
|
|
688
|
-
if (hideReadOnlyProperties || hideWriteOnlyProperties) {
|
|
689
|
-
if
|
|
688
|
+
if ((hideReadOnlyProperties || hideWriteOnlyProperties) && !Object.keys(newPropSchema).length) {
|
|
689
|
+
// We should only delete this schema if it wasn't already empty though. We do this
|
|
690
|
+
// because we (un)fortunately have handling in our API Explorer form system for
|
|
691
|
+
// schemas that are devoid of any `type` declaration.
|
|
692
|
+
if (Object.keys(schema.properties[prop]).length > 0) {
|
|
690
693
|
delete schema.properties[prop];
|
|
694
|
+
} else {
|
|
695
|
+
schema.properties[prop] = newPropSchema;
|
|
691
696
|
}
|
|
697
|
+
} else {
|
|
698
|
+
schema.properties[prop] = newPropSchema;
|
|
692
699
|
}
|
|
693
700
|
}
|
|
694
701
|
});
|
|
@@ -779,6 +786,14 @@ export default function toJSONSchema(
|
|
|
779
786
|
|
|
780
787
|
// Only add a default value if we actually have one.
|
|
781
788
|
if ('default' in schema && typeof schema.default !== 'undefined') {
|
|
789
|
+
// If it's an enum and not the response schema, add the default to the description.
|
|
790
|
+
// If there's an existing description, trim trailing new lines so it doesn't look ugly.
|
|
791
|
+
if ('enum' in schema && !addEnumsToDescriptions) {
|
|
792
|
+
schema.description = schema.description
|
|
793
|
+
? `${schema.description.replace(/\n$/, '')}\n\nDefault: ${schema.default}`
|
|
794
|
+
: `Default: ${schema.default}`;
|
|
795
|
+
}
|
|
796
|
+
|
|
782
797
|
if (('allowEmptyValue' in schema && schema.allowEmptyValue && schema.default === '') || schema.default !== '') {
|
|
783
798
|
// If we have `allowEmptyValue` present, and the default is actually an empty string, let it
|
|
784
799
|
// through as it's allowed.
|