-
Notifications
You must be signed in to change notification settings - Fork 146
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
default value for array items #367
Comments
I can make a PR if needed, but I don't have any clue how to do it properly |
In my fork, I did: A-312@c9d2410#diff-9a1c05ec2f523aa189f25a817c2b605dR368-R381 (It is maybe usefull to have a different messages displays when you want return several error). Like this:
You have to had the fullName variable like a third arg: node-convict/packages/convict/src/main.js Line 298 in 903638f
|
Thanks for answer. I already tried with fullname but it's not enough if I have sub array. I will give a try |
I think my solution handle this |
it works by adding fullname and instance, thanks :) export default {
name: 'source-array',
validate: (
sources: any,
schema: { children: string | convict.Schema<any> },
fullname: string,
instance: convict.Config<any>,
) => {
if (!Array.isArray(sources)) {
throw new Error('must be of type Array');
}
const data = sources.map(source =>
convict(schema.children)
.load(source)
.validate({ allowed: 'strict' })
.getProperties();
);
instance.set(fullname, data);
},
}; I forked node-convict to do it, but I can create a PR on your project if you want ? |
or: and after: |
yes, good idea too ! |
Is there any fix available for this issue yet ,i am facing similar issue ,default values of children array objects are not being loading after upgrade to 6.0.1 ? |
Hello,
i'm using the array validator in my schema.
Unfortunately, because it use a new convict instance to validate the schema, the default values of the elements in my array are not set.
I tried to get my active instance, but because I don't know where i am in the schema during the validation, I can't set the values on my own.
If someone as any idea ?
this is the validator:
my schema:
my config file:
what I want:
what I have:
The text was updated successfully, but these errors were encountered: