Skip to content

Custom validator not called on root schemas #137

@mihaispataru

Description

@mihaispataru

Hi,

i've come across an issue with the custom validator on root object schemas.

The custom validator is not handled when we create a root object schema.

const schemaRoot = {
  type: 'object',
  $$root: true,
  props: {
    prop1: { type: 'string', optional: true },
    prop2: { type: 'string', optional: true },
  },
  custom: (v, errors, schema, object) => {
    console.log(v, errors, schema, object);
    return v;
  }
};

The result when validating the schema is:

--------------------
ROOT object test
--------------------

Data: { prop1: '' }
Schema: {
  type: 'object',
  '$$root': true,
  props: {
    prop1: { type: 'string', optional: true },
    prop2: { type: 'string', optional: true }
  },
  custom: [Function: custom]
}
Validate Result: true

I've created a repl.it repository with test demo.

Repl.it Demo

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