enjoi
enjoi copied to clipboard
"abortEarly" does not work with "allOf"
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,
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.