Skip to content

Commit 261b73b

Browse files
authored
Merge pull request #3839 from heldersepu/bug/validation-messages
Fix issue with the error messages
2 parents b3e86b3 + 4315cf6 commit 261b73b

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/core/utils.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,19 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
488488
Only bother validating the parameter if the type was specified.
489489
*/
490490
if ( type && (required || value) ) {
491-
// These checks should evaluate to true if the parameter's value is valid
492-
let stringCheck = type === "string" && value && !validateString(value)
491+
// These checks should evaluate to true if there is a parameter
492+
let stringCheck = type === "string" && value
493493
let arrayCheck = type === "array" && Array.isArray(value) && value.length
494494
let listCheck = type === "array" && Im.List.isList(value) && value.count()
495495
let fileCheck = type === "file" && value instanceof win.File
496-
let booleanCheck = type === "boolean" && !validateBoolean(value)
497-
let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number
498-
let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer
496+
let booleanCheck = type === "boolean" && (value || value === false)
497+
let numberCheck = type === "number" && value
498+
let integerCheck = type === "integer" && value
499+
500+
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
501+
errors.push("Required field is not provided")
502+
return errors
503+
}
499504

500505
if (pattern) {
501506
let err = validatePattern(value, pattern)
@@ -512,11 +517,6 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
512517
if (err) errors.push(err)
513518
}
514519

515-
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
516-
errors.push("Required field is not provided")
517-
return errors
518-
}
519-
520520
if (maximum || maximum === 0) {
521521
let err = validateMaximum(value, maximum)
522522
if (err) errors.push(err)

test/core/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ describe("utils", function() {
548548
type: "boolean",
549549
value: "test string"
550550
}
551-
assertValidateParam(param, ["Required field is not provided"])
551+
assertValidateParam(param, ["Value must be a boolean"])
552552

553553
// valid boolean value
554554
param = {
@@ -608,7 +608,7 @@ describe("utils", function() {
608608
type: "number",
609609
value: "test"
610610
}
611-
assertValidateParam(param, ["Required field is not provided"])
611+
assertValidateParam(param, ["Value must be a number"])
612612

613613
// invalid number, undefined value
614614
param = {
@@ -690,7 +690,7 @@ describe("utils", function() {
690690
type: "integer",
691691
value: "test"
692692
}
693-
assertValidateParam(param, ["Required field is not provided"])
693+
assertValidateParam(param, ["Value must be an integer"])
694694

695695
// invalid integer, undefined value
696696
param = {

0 commit comments

Comments
 (0)