Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"abortEarly" does not work with "allOf" #58

Open
ozum opened this issue Aug 29, 2018 · 1 comment
Open

"abortEarly" does not work with "allOf" #58

ozum opened this issue Aug 29, 2018 · 1 comment

Comments

@ozum
Copy link

ozum commented Aug 29, 2018

When used with allOf, abortEarly does not work. I suppose it is related to Joi extension for allOf.

I pasted a minimal sample code below:

Example Code

const Joi = require("joi");
const Enjoi = require("enjoi");

const jsonSchema = {
  allOf: [
    {
      allOf: [
        {
          type: "object",
          properties: {
            a: { type: "string" },
            b: { type: "string" },
          },
          required: ["a", "b"],
        },
        {
          type: "object",
          properties: {
            c: { type: "string" },
            d: { type: "string" },
          },
          required: ["d"],
        },
      ],
    },
  ],
};

const jsonSchema2 = {
  type: "object",
  properties: {
    a: { type: "string" },
    b: { type: "string" },
  },
  required: ["a", "b"],
};

const result = Joi.validate({}, Enjoi.schema(jsonSchema), { abortEarly: false });
const result2 = Joi.validate({}, Enjoi.schema(jsonSchema2), { abortEarly: false });

console.log(result.error);
console.log(result2.error);

Actual Result

result.error has single error.
result2.error has multiple errors.

Expected Result

result.error has multiple error.
result2.error has multiple errors.

Kind Regards,

@tlivings
Copy link
Owner

Unfortunately it may not be possible to do this. The reason is, through extend we are supposed to use createError or createOverrideError to return an error. This returns a single error...

If we want to have multiple errors then we need access to Error.process(errors, ...) and this is not exposed AFAIK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants