Skip to content

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

@anthonyG78

Description

@anthonyG78

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions