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

Maximum call stack size exceeded #1109

Closed
DardanHaliti opened this issue Oct 24, 2019 · 4 comments
Closed

Maximum call stack size exceeded #1109

DardanHaliti opened this issue Oct 24, 2019 · 4 comments
Labels

Comments

@DardanHaliti
Copy link

DardanHaliti commented Oct 24, 2019

What version of Ajv are you using? Does the issue happen if you use the latest version?
I am using the latest version of ajv.
The project structure is src/schemas/schemaA.json and src/scripts/app.js

Ajv options object
I have read those links:
#802
#801
#877

JSON Schema

I have a json file schemaA.json

{
    "$id":"/path/to/file/schemaA.json",
    "$schema": "http://json-schema.org/draft-07/schema",
    "$ref": "/path/to/filer/schemaA.json",
    "schemaA": {
        "title": "P&ID Node Symbol",
        "description": "schemaA description",
        "type": "object",
        "properties": {
            "depiction": {
                "type": "string",
                "description": "another description"
            }
        },
        "required": ["depiction"]
    }
}

Sample data

For testing it is just a empty object or sometimes a simple example

{}
//
{
    "data":"123"
}

Your code

let Ajv = require('ajv');
let ajv = new Ajv({allErrors: true, schemaId: 'auto'});
let jsh = JSON.parse(fs.readFileSync("../src/server/schemas/nodeSymbol.json", 'utf8'));
ajv.addSchema(jsh);
// In a class method i use
async classmethod(req, res)
{
        //...other code not related to ajv
        let validate = ajv.compile(this.jsonschema);
        let v = validate({}); // here happens the error
        console.log(v)
        //..other code not related to ajv
}

Validation result, data AFTER validation, error messages

UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
    at callValidate (/app/node_modules/ajv/lib/ajv.js:1:1)
    at validate (eval at localCompile (/app/node_modules/ajv/lib/compile/index.js:120:26), <anonymous>:3:221)
    at callValidate (/app/node_modules/ajv/lib/ajv.js:368:28)
    at validate (eval at localCompile (/app/node_modules/ajv/lib/compile/index.js:120:26), <anonymous>:3:221)


What results did you expect?
I expect true or false when i try to validate it. I tried with compileAsync too but still the same problem.
Ps. I cant change the label to green

Are you going to resolve the issue?

@epoberezkin
Copy link
Member

The schema is self-referencing from the top level - it is equivalent to the function function a() { return a(); } - endless recursion without the exit in case of success (and without the exit in case of failure when you use allErrors: true option). It is supposed to exceed the stack.

@epoberezkin
Copy link
Member

Assuming that "$ref": "/path/to/filer/schemaA.json" is a typo and should be "$ref": "/path/to/file/schemaA.json"

@DardanHaliti
Copy link
Author

Hi @epoberezkin thanks about the clearance of exceeded stack problem, I solved the error by adding "#/" to the end where the "$ref" points.
Another question is by adding multiple schemas, can i compile them at once or do i need to merge them? because when i add them and then try to validate my json object then it always returns true even when the data is an empty json(in which it should return false).

@epoberezkin
Copy link
Member

I don’t think I understand but it’s good you resolved it :)

It’s difficult to understand the problem without code sample - I think you may be using api incorrectly

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

No branches or pull requests

2 participants