diff --git a/src/core/json-schema-components.jsx b/src/core/json-schema-components.jsx
index f531341e312..25a09d9cb4f 100644
--- a/src/core/json-schema-components.jsx
+++ b/src/core/json-schema-components.jsx
@@ -345,6 +345,31 @@ export class JsonSchema_boolean extends Component {
}
}
+const stringifyObjectErrors = (errors) => {
+ return errors.map(err => {
+ const meta = err.propKey !== undefined ? err.propKey : err.index
+ let stringError = typeof err === "string" ? err : typeof err.error === "string" ? err.error : null
+
+ if(!meta && stringError) {
+ return stringError
+ }
+ let currentError = err.error
+ let path = `/${err.propKey}`
+ while(typeof currentError === "object") {
+ const part = currentError.propKey !== undefined ? currentError.propKey : currentError.index
+ if(part === undefined) {
+ break
+ }
+ path += `/${part}`
+ if (!currentError.error) {
+ break
+ }
+ currentError = currentError.error
+ }
+ return `${path}: ${currentError}`
+ })
+}
+
export class JsonSchema_object extends PureComponent {
constructor() {
super()
@@ -372,18 +397,18 @@ export class JsonSchema_object extends PureComponent {
} = this.props
const TextArea = getComponent("TextArea")
+ errors = errors.toJS ? errors.toJS() : Array.isArray(errors) ? errors : []
return (
)
-
}
}
diff --git a/src/core/utils.js b/src/core/utils.js
index a8bcdcde905..771da4d0ec9 100644
--- a/src/core/utils.js
+++ b/src/core/utils.js
@@ -453,7 +453,7 @@ function validateValueBySchema(value, schema, isParamRequired, bypassRequiredChe
Only bother validating the parameter if the type was specified.
in case of array an empty value needs validation too because constrains can be set to require minItems
*/
- if (type && (isParamRequired || required || value || type === "array" && !value)) {
+ if (type && (isParamRequired || required || value !== undefined || type === "array")) {
// These checks should evaluate to true if there is a parameter
let stringCheck = type === "string" && value
let arrayCheck = type === "array" && Array.isArray(value) && value.length
@@ -477,18 +477,33 @@ function validateValueBySchema(value, schema, isParamRequired, bypassRequiredChe
errors.push("Required field is not provided")
return errors
}
-
if (
type === "object" &&
- typeof value === "string" &&
(parameterContentMediaType === null ||
parameterContentMediaType === "application/json")
) {
- try {
- JSON.parse(value)
- } catch (e) {
- errors.push("Parameter string value must be valid JSON")
- return errors
+ let objectVal = value
+ if(typeof value === "string") {
+ try {
+ objectVal = JSON.parse(value)
+ } catch (e) {
+ errors.push("Parameter string value must be valid JSON")
+ return errors
+ }
+ }
+ if(schema && schema.has("required") && isFunc(required.isList) && required.isList()) {
+ required.forEach(key => {
+ if(objectVal[key] === undefined) {
+ errors.push({ propKey: key, error: "Required property not found" })
+ }
+ })
+ }
+ if(schema && schema.has("properties")) {
+ schema.get("properties").forEach((val, key) => {
+ const errs = validateValueBySchema(objectVal[key], val, false, bypassRequiredCheck, parameterContentMediaType)
+ errors.push(...errs
+ .map((error) => ({ propKey: key, error })))
+ })
}
}