Skip to content

Inconsistent "schemaPath" for errors #262

@varoot

Description

@varoot

schemaPath that were returned from validateResult are not always consistent. For example, multipleOf rule are not included:

const schema = {
  type: 'object',
  properties: {
    num: {
      type: 'number',
      minimum: 5,
      multipleOf: 2,
    },
  },
};

// schemaPath missing "multipleOf"
tv4.validateResult({ num: 1 }, schema);
// {
//   error: {
//     message: "Value 1 is not a multiple of 2",
//     params: {
//       value: 1,
//       multipleOf: 2
//     },
//     code: 100,
//     dataPath: "/num",
//     schemaPath: "/properties/num",
//     subErrors: null,
//     stack: "(...omitted...)"
//   },
//   missing: [],
//   valid: false
// }

tv4.validateResult({ num: 2 }, schema);
// {
//   error: {
//     message: "Value 2 is less than minimum 5",
//     params: {
//       value: 2,
//       minimum: 5
//     },
//     code: 101,
//     dataPath: "/num",
//     schemaPath: "/properties/num/minimum",
//     subErrors: null,
//     stack: "(...omitted...)"
//   },
//   missing: [],
//   valid: false
// }

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