Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Nested object in array should validate individually #1627

Open
6 tasks done
Hideman85 opened this issue Aug 7, 2023 · 0 comments
Open
6 tasks done

[BUG] Nested object in array should validate individually #1627

Hideman85 opened this issue Aug 7, 2023 · 0 comments

Comments

@Hideman85
Copy link

Summary:

Dynamoose force nested object of array to have the same type instead of one of the valid type individually

Code sample:

const model = dynamoose.model('test', {
  arr: [{
    type: Array,
    schema: [{
      type: Object,
      schema: {
        foo: [Number, dynamoose.type.NULL]
      }
    }]
  }, dynamoose.type.NULL]
});

//  Pass
await new model({ arr: [{ foo: 1 }, { foo: 2 }] }).conformToSchema({
  customTypesDynamo: true,
  checkExpiredItem: true,
  saveUnknown: true,
  modifiers: ['get'],
  type: 'fromDynamo',
})

//  Pass
await new model({ arr: [{ foo: null }, { foo: null }] }).conformToSchema({
  customTypesDynamo: true,
  checkExpiredItem: true,
  saveUnknown: true,
  modifiers: ['get'],
  type: 'fromDynamo',
})

//  Should pass but Throw Invalid TypeMismatch: Expected arr.1.foo to be of type number, instead found type null.
await new model({ arr: [{ foo: 1 }, { foo: null }] }).conformToSchema({
  customTypesDynamo: true,
  checkExpiredItem: true,
  saveUnknown: true,
  modifiers: ['get'],
  type: 'fromDynamo',
})

console.info('Pass')

Environment:

Operating System: Ubuntu 23.04
Node.js version (node -v): v18.17.0
Dynamoose version: 3.2.0

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn't been raised or answered before
  • I have tested the code provided and am confident it doesn't work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant