kristianmandrup / schema-to-yup

Schema to Yup validation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nullable value not evaulated properly

d-lach opened this issue · comments

I receive an error message:
image

however the field is marked as nullable in the schema:

{
  type: 'object',
  nullable: true,
  required: false,
  properties: {
    (...)
  }
}

This is the constraint logic for applying nullable (in mixed.js) where value is the actual JSON schema constraint object (ie in terms of key/value) where key is the property name.

  nullable() {
    const nullable = this.value.nullable === true;
    this.base = (nullable && this.base.nullable()) || this.base;
    return this;
  }

nullable methid should be called since it is part of

  get mixedEnabled() {
    return (
      this.mixedConfig.enabled || [
        "oneOf",
        "notOneOf",
        "when",
        "nullable",
        "isType",
        "label",
        "const",
        "refValueFor",
      ]
    );
  }
  get enabled() {
    return [...this.mixedEnabled, ...this.$typeEnabled];
  }

  convertEnabled() {
    this.enabled.map((name) => {
      const convertFn = this.convertFnFor(name);
      if (convertFn) {
        convertFn(this);
      }
    });
  }

You can debug it by applying detailed logging as described in the docs

The branch nullable now has tests to verify that nullable constraint should work as expected

Please see PR - #143