enjoi
enjoi copied to clipboard
[Bug] Using a $ref in a anyOf or allOf triggers a RangeError
Hi,
Using a $ref
in a anyOf
or an affOf
in a schema triggers the following error:
RangeError: Maximum call stack size exceeded
Code to reproduce
const Enjoi = require('enjoi');
const jsonSchema = {
allOf: [
{
$ref: "#/components/schemas/TestObject"
},
{
type: 'object',
properties: {
info: {
type: 'string'
}
}
}
]
};
const subSchemas = {
components:{
schemas: {
TestObject:{
additionalProperties: false,
type: 'object',
properties:{
id: {
type: 'number'
},
name:{
type: 'string'
},
subobject:{
$ref: "#/components/schemas/TestSubObject"
},
type:{
type: 'string',
enum: [
'AUDIENCE',
'CAMPAIGN'
]
}
}
},
TestSubObject:{
additionalProperties: false,
type: 'object',
properties:{
id:{
type: 'number'
},
name:{
type: 'string'
}
}
}
}
}
};
const schema = Enjoi.schema(jsonSchema, { subSchemas });
const options = {
allowUnknown: false,
abortEarly: false,
stripUnknown: false
};
const result = schema.validate({
id: 7,
name: 'test',
type: 'AUDIENCE',
info: 'good'
}, options);
console.log('res', result);
Expected result
The validation should be able to handle $refs
in anyOf
or allOf
Thanks in advance!