Skip to content

Commit ec2179f

Browse files
committed
Fix issue with the error messages
Many of the errors where incorrectly showing "Required field is not provided" when the field was provided but not valid. This was raised by @ron on PR #3825
1 parent 4eae9b6 commit ec2179f

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
@@ -556,14 +556,19 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
556556
Only bother validating the parameter if the type was specified.
557557
*/
558558
if ( type && (required || value) ) {
559-
// These checks should evaluate to true if the parameter's value is valid
560-
let stringCheck = type === "string" && value && !validateString(value)
559+
// These checks should evaluate to true if there is a parameter
560+
let stringCheck = type === "string" && value
561561
let arrayCheck = type === "array" && Array.isArray(value) && value.length
562562
let listCheck = type === "array" && Im.List.isList(value) && value.count()
563563
let fileCheck = type === "file" && value instanceof win.File
564-
let booleanCheck = type === "boolean" && !validateBoolean(value)
565-
let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number
566-
let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer
564+
let booleanCheck = type === "boolean" && (value || value === false)
565+
let numberCheck = type === "number" && value
566+
let integerCheck = type === "integer" && value
567+
568+
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
569+
errors.push("Required field is not provided")
570+
return errors
571+
}
567572

568573
if (maxLength || maxLength === 0) {
569574
let err = validateMaxLength(value, maxLength)
@@ -575,11 +580,6 @@ export const validateParam = (param, isXml, isOAS3 = false) => {
575580
if (err) errors.push(err)
576581
}
577582

578-
if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
579-
errors.push("Required field is not provided")
580-
return errors
581-
}
582-
583583
if (maximum || maximum === 0) {
584584
let err = validateMaximum(value, maximum)
585585
if (err) errors.push(err)

test/core/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ describe("utils", function() {
524524
type: "boolean",
525525
value: "test string"
526526
}
527-
assertValidateParam(param, ["Required field is not provided"])
527+
assertValidateParam(param, ["Value must be a boolean"])
528528

529529
// valid boolean value
530530
param = {
@@ -584,7 +584,7 @@ describe("utils", function() {
584584
type: "number",
585585
value: "test"
586586
}
587-
assertValidateParam(param, ["Required field is not provided"])
587+
assertValidateParam(param, ["Value must be a number"])
588588

589589
// invalid number, undefined value
590590
param = {
@@ -666,7 +666,7 @@ describe("utils", function() {
666666
type: "integer",
667667
value: "test"
668668
}
669-
assertValidateParam(param, ["Required field is not provided"])
669+
assertValidateParam(param, ["Value must be an integer"])
670670

671671
// invalid integer, undefined value
672672
param = {

0 commit comments

Comments
 (0)