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

Array default ignored: array default always = [] #51

Open
anthonyG78 opened this issue Feb 14, 2019 · 0 comments
Open

Array default ignored: array default always = [] #51

anthonyG78 opened this issue Feb 14, 2019 · 0 comments

Comments

@anthonyG78
Copy link

According to the Mongoose arrays documentation, an array default value is possible.
But in schm, when array of schema is validatate, the default value is always an empty array.

Inspired example from Mongoose

const ToySchema = schm({ name: String });
const ToyBoxSchema = schm({
  toys: {
    type: [ToySchema],
    default: undefined
  },
  buffers: [Buffer],
  strings: [String],
  numbers: [Number]
});

const result = await ToyBoxSchema.validate({
  // Validate empty object
});

console.log(result); 
// result = { toys: [], buffers: [], strings: [], numbers: [] }
// Expected: result =  { toys: undefined, buffers: [], strings: [], numbers: [] }

Any idea to get a custom default value rather than an empty array?
Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant