Skip to content

Commit

Permalink
fix(utils): fix validation for required values without specified type
Browse files Browse the repository at this point in the history
Refs #8007
  • Loading branch information
glowcloud committed Apr 22, 2024
1 parent cf7b769 commit ca9f05a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/core/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,26 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe

const isValidNullable = nullable && value === null

// required value is not provided and there's no type defined in the schema
const requiredNotProvided =
schemaRequiresValue
&& !hasValue
&& !isValidNullable
&& !bypassRequiredCheck
&& !type

if (requiredNotProvided) {
errors.push("Required field is not provided")
return errors
}

// will not be included in the request or [schema / value] does not [allow / require] further analysis.
const noFurtherValidationNeeded =
isValidNullable
|| !type
|| !requiresFurtherValidation

if(noFurtherValidationNeeded) {
if (noFurtherValidationNeeded) {
return []
}

Expand Down
16 changes: 16 additions & 0 deletions test/unit/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,22 @@ describe("utils", () => {
value = 10
assertValidateParam(param, value, [])
})

it("validates required parameters without schema", () => {
// valid value
param = {
required: true
}
value = 123
assertValidateParam(param, value, [])

// missing value
param = {
required: true
}
value = undefined
assertValidateParam(param, value, ["Required field is not provided"])
})
})

describe("fromJSOrdered", () => {
Expand Down

0 comments on commit ca9f05a

Please sign in to comment.