Merge pull request #3839 from heldersepu/bug/validation-messages

Fix issue with the error messages
This commit is contained in:
kyle
2017-11-03 17:23:44 -07:00
committed by GitHub
2 changed files with 13 additions and 13 deletions

View File

@@ -488,14 +488,19 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
Only bother validating the parameter if the type was specified. Only bother validating the parameter if the type was specified.
*/ */
if ( type && (required || value) ) { if ( type && (required || value) ) {
// These checks should evaluate to true if the parameter's value is valid // These checks should evaluate to true if there is a parameter
let stringCheck = type === "string" && value && !validateString(value) let stringCheck = type === "string" && value
let arrayCheck = type === "array" && Array.isArray(value) && value.length let arrayCheck = type === "array" && Array.isArray(value) && value.length
let listCheck = type === "array" && Im.List.isList(value) && value.count() let listCheck = type === "array" && Im.List.isList(value) && value.count()
let fileCheck = type === "file" && value instanceof win.File let fileCheck = type === "file" && value instanceof win.File
let booleanCheck = type === "boolean" && !validateBoolean(value) let booleanCheck = type === "boolean" && (value || value === false)
let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number let numberCheck = type === "number" && value
let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer let integerCheck = type === "integer" && value
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
errors.push("Required field is not provided")
return errors
}
if (pattern) { if (pattern) {
let err = validatePattern(value, pattern) let err = validatePattern(value, pattern)
@@ -512,11 +517,6 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
if (err) errors.push(err) if (err) errors.push(err)
} }
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
errors.push("Required field is not provided")
return errors
}
if (maximum || maximum === 0) { if (maximum || maximum === 0) {
let err = validateMaximum(value, maximum) let err = validateMaximum(value, maximum)
if (err) errors.push(err) if (err) errors.push(err)

View File

@@ -548,7 +548,7 @@ describe("utils", function() {
type: "boolean", type: "boolean",
value: "test string" value: "test string"
} }
assertValidateParam(param, ["Required field is not provided"]) assertValidateParam(param, ["Value must be a boolean"])
// valid boolean value // valid boolean value
param = { param = {
@@ -608,7 +608,7 @@ describe("utils", function() {
type: "number", type: "number",
value: "test" value: "test"
} }
assertValidateParam(param, ["Required field is not provided"]) assertValidateParam(param, ["Value must be a number"])
// invalid number, undefined value // invalid number, undefined value
param = { param = {
@@ -690,7 +690,7 @@ describe("utils", function() {
type: "integer", type: "integer",
value: "test" value: "test"
} }
assertValidateParam(param, ["Required field is not provided"]) assertValidateParam(param, ["Value must be an integer"])
// invalid integer, undefined value // invalid integer, undefined value
param = { param = {