Defect - TypeError: Cannot read property 'schema' of undefined
Closed this issue · 2 comments
mamendoz commented
Doing a quick test to see if I can use djv to validate Swagger 2.0.
Using djv@1.0.0-beta.0
:
Here is the sample script:
var djv = require("djv");
var fs = require("fs");
var JSONSchemaDraftV4 = JSON.parse(fs.readFileSync("./json-schema-draft-v4.json"));
var Swagger2 = JSON.parse(fs.readFileSync("./swagger2.json"));
var env = new djv();
env.addSchema("json-schema-draft-v4", JSONSchemaDraftV4);
env.addSchema("swagger2", Swagger2);
env.validate('swagger2', {});
Here is the output when running it:
$ node test.js
/opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/utils.js:156
currentSchema = state[uri].schema;
^
TypeError: Cannot read property 'schema' of undefined
at Object.resolve (/opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/utils.js:156:35)
at Function.resolve (/opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/generate.js:15:35)
at $ref (/opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/validators/$ref.js:6:20)
at /opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/generate.js:83:53
at Array.forEach (native)
at Function.visit (/opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/generate.js:82:15)
at properties (/opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/validators/properties.js:18:12)
at /opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/generate.js:83:53
at Array.forEach (native)
at Function.visit (/opt/node-v6.9.5-linux-x64/lib/node_modules/djv/lib/generate.js:82:15)
Files used in script:
korzio commented
@mamendoz I've started working on it - 048fec7 . So, I've tried a simple fix with adding an id to a resolved schemas space. But apparently, the problem is bigger - so now, it can find a json-schema in a scope, but it exceeds a call stack limit. I'll go further to update a resolving algorithm, and this story is already in backlog.