Browse Source

Add validateDateTime & validateGuid

Initial work to tacke some of the missing validation (Issue #993)
bubble
HelderSepu 7 years ago
parent
commit
85b7b7241d
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      src/core/utils.js

+ 21
- 1
src/core/utils.js View File

@@ -500,12 +500,25 @@ export const validateString = ( val ) => {
}
}

export const validateDateTime = (val) => {
if (val && typeof val !== "string") {
return "Value must be a DateTime"
}
}

export const validateGuid = (val) => {
if (val && typeof val !== "string") {
return "Value must be a Guid"
}
}

// validation of parameters before execute
export const validateParam = (param, isXml) => {
let errors = []
let value = isXml && param.get("in") === "body" ? param.get("value_xml") : param.get("value")
let required = param.get("required")
let type = param.get("type")
let format = param.get("format")

/*
If the parameter is required OR the parameter has a value (meaning optional, but filled in)
@@ -528,7 +541,14 @@ export const validateParam = (param, isXml) => {
}

if ( type === "string" ) {
let err = validateString(value)
let err
if (format === "date-time") {
err = validateDateTime(value)
} else if (format === "uuid") {
err = validateGuid(value)
} else {
err = validateString(value)
}
if (!err) return errors
errors.push(err)
} else if ( type === "boolean" ) {


Loading…
Cancel
Save