What version of Ajv are you using? Does the issue happen if you use the latest version?
6.5.0
Ajv options object
JSON Schema
function Default() {}
Default.prototype.toJSON = function toJSON() {
return {};
};
const def = new Default;
def.prop = {
Default: def // it fails because of this circular enumerable property
};
const schema = {
type: 'object',
properties: {
prop: {
type: 'object',
default: def
}
}
};
Your code
ajv.addSchema(schema, 'test');
Validation result, data AFTER validation, error messages
RangeError: Maximum call stack size exceeded
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:58:5)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
at _traverse (/path/to/project/node_modules/json-schema-traverse/index.js:72:9)
What results did you expect?
When useDefaults=false I'd expect that ajv is gonna ignore default keyword and not traverse its enumerable properties.
Although it should not fail even with useDefaults=true when the default value object implements toJSON method.
Are you going to resolve the issue?
possible bugfix provided here:
epoberezkin/json-schema-traverse#5
In ajv library, used here:
https://github.com/epoberezkin/ajv/blob/master/lib/compile/resolve.js#L239
What version of Ajv are you using? Does the issue happen if you use the latest version?
6.5.0Ajv options object
JSON Schema
Your code
Validation result, data AFTER validation, error messages
What results did you expect?
When
useDefaults=falseI'd expect thatajvis gonna ignoredefaultkeyword and not traverse its enumerable properties.Although it should not fail even with
useDefaults=truewhen the default value object implementstoJSONmethod.Are you going to resolve the issue?
possible bugfix provided here:
epoberezkin/json-schema-traverse#5
In ajv library, used here:
https://github.com/epoberezkin/ajv/blob/master/lib/compile/resolve.js#L239