Array default ignored: array default always = []
- Dominant language
- JavaScript
- Stars
- 511
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
According to the [Mongoose arrays documentation](https://mongoosejs.com/docs/schematypes.html#arrays), 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
```javascript
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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the documented example with the array schema and `default: undefined`, then locate the array-default handling in the validation code. Done means an explicitly undefined default is preserved while unspecified array fields still receive empty arrays, with coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100