Skip to content

Get default value of a property of an object when the object is an array item #403

@vaidkaran

Description

@vaidkaran

I am trying to get the default value of pathFilter via convict.default()
Below is my configSchema

  masks: {
    format: 'Object',
    body: {
      doc: 'masks for body',
      format: 'Array',
      default: [],
      children: {
        pathFilter: {
          format: RegExp,
          doc: 'Filter for applying mask to certain paths',
          default: /.*/,
        },
      },
    },
  },

And the config looks like:

    masks: {
      body: [
        {
          pathFilter: /xyz/,
        },
      ],
    }

I tried doing config.default('masks.body.children.pathFilter') but that doesn't work.
One problem that I see here is that we add and look for _cvtProperties under arrays too. Arrays seem to have children and not _cvtProperties. So the default function would resolve the path and look for body._cvtProperties but it won't exist.

Maybe we need to cater for arrays here

Please advise.

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