Skip to content

default value for array items #367

@Darkein

Description

@Darkein

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:

convict.addFormat({
  name: 'source-array',
  validate: function(sources, schema) {
   /* ... */
    for (source of sources) {
      convict(schema.children).load(source).validate();
    }
  }
});

my schema:

defaultValue:
  format: String
  default: 'default'
contexts:
  format: array
  default: []
  children:
    defaultValue:
      format: String
      default: 'default'
    name:
      format: String
      default: null

my config file:

contexts:
  - name: TEST1

what I want:

{
   "defaultValue": "default",
   "contexts":[
      {
         "defaultValue": "default",
         "name": "TEST1"
      }
   ]
}

what I have:

{
   "defaultValue": "default",
   "contexts":[
      {
         "name": "TEST1"
      }
   ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions