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

[Bug] Using a $ref in a anyOf or allOf triggers a RangeError #110

Open
Vladirien opened this issue Jan 18, 2021 · 0 comments
Open

[Bug] Using a $ref in a anyOf or allOf triggers a RangeError #110

Vladirien opened this issue Jan 18, 2021 · 0 comments

Comments

@Vladirien
Copy link

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!

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

1 participant