Skip to content

Commit

Permalink
Fixing required bug with multiple types for single attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed Dec 19, 2020
1 parent 0dc5812 commit 721c74a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Schema.ts
Expand Up @@ -612,7 +612,7 @@ Schema.prototype.getRangeKey = function (this: Schema): string | void {
// This function will take in an attribute and value, and throw an error if the property is required and the value is undefined or null.
Schema.prototype.requiredCheck = async function (this: Schema, key: string, value: ValueType): Promise<void> {
const isRequired = await this.getAttributeSettingValue("required", key);
if ((typeof value === "undefined" || value === null) && (isRequired)) {
if ((typeof value === "undefined" || value === null) && (Array.isArray(isRequired) ? isRequired.some((val) => Boolean(val)) : isRequired)) {
throw new CustomError.ValidationError(`${key} is a required property but has no value when trying to save document`);
}
};
Expand Down
5 changes: 5 additions & 0 deletions test/unit/Document.js
Expand Up @@ -2458,6 +2458,11 @@ describe("Document", () => {
"schema": {"id": Number, "data": [Number, String]},
"output": {"id": 1, "data": 2}
},
{
"input": [{"id": 1}, {"type": "fromDynamo", "required": true}],
"schema": {"id": Number, "data": [Number, String]},
"output": {"id": 1}
},
{
"schema": {"id": Number, "other": [{"type": "Combine"}, String]},
"input": [{"id": 1}, {"type": "toDynamo", "combine": true}],
Expand Down

0 comments on commit 721c74a

Please sign in to comment.