diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index 24dcde3c2fa1..71fe89023b29 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -133,7 +133,7 @@ const RequestBody = ({ { - Map.isMap(bodyProperties) && bodyProperties.entrySeq().map(([key, prop]) => { + Map.isMap(bodyProperties) && bodyProperties.entrySeq().map(([key, prop]) => { if (prop.get("readOnly")) return let commonExt = showCommonExtensions ? getCommonExtensions(prop) : null @@ -143,67 +143,65 @@ const RequestBody = ({ const description = prop.get("description") const currentValue = requestBodyValue.getIn([key, "value"]) const currentErrors = requestBodyValue.getIn([key, "errors"]) || requestBodyErrors - - let initialValue = prop.get("default") || prop.get("example") || "" - - if (initialValue === "") { - if(type === "object") { - initialValue = getSampleSchema(prop, false, { - includeWriteOnly: true - }) - } else if(type === "array") { - initialValue = [] - } + const included = requestBodyInclusionSetting.get(key) || false + let hasNonEmptyInitialVal = prop.has("default") || prop.has("example")|| prop.has("enum") && prop.get("enum").size === 1 + let initialValue = "" + if(type === "array") { + initialValue = [] + } else if (hasNonEmptyInitialVal) { + // TODO: what about example or examples from requestBody could be passed as exampleOverride + initialValue = getSampleSchema(prop, false, { + includeWriteOnly: true + }) } - if (typeof initialValue !== "string" && type === "object") { - initialValue = stringify(initialValue) + initialValue = stringify(initialValue) } const isFile = type === "string" && (format === "binary" || format === "base64") return - - - + + + }) }
-
- { key } - { !required ? null :  * } -
-
- { type } - { format && (${format})} - {!showCommonExtensions || !commonExt.size ? null : commonExt.entrySeq().map(([key, v]) => )} -
-
- { prop.get("deprecated") ? "deprecated": null } -
-
- - {isExecute ?
- { - onChange(value, [key]) - }} - /> - {required ? null : ( - onChangeIncludeEmpty(key, value)} - isIncluded={requestBodyInclusionSetting.get(key) || false} - isIncludedOptions={setIsIncludedOptions(key)} - isDisabled={Array.isArray(currentValue) ? currentValue.length !== 0 : !isEmptyValue(currentValue)} - /> - )} -
: null } -
+
+ { key } + { !required ? null :  * } +
+
+ { type } + { format && (${format})} + {!showCommonExtensions || !commonExt.size ? null : commonExt.entrySeq().map(([key, v]) => )} +
+
+ { prop.get("deprecated") ? "deprecated": null } +
+
+ + {isExecute ?
+ { + onChange(value, [key]) + }} + /> + {required ? null : ( + onChangeIncludeEmpty(key, value)} + isIncluded={included} + isIncludedOptions={setIsIncludedOptions(key)} + isDisabled={Array.isArray(currentValue) ? currentValue.length !== 0 : !isEmptyValue(currentValue)} + /> + )} +
: null } +