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
  • Loading branch information
glowcloud authored Apr 23, 2024
1 parent cf7b769 commit 6fccf9e
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 6fccf9e

Please sign in to comment.