natesilva / jayschema

[Unmaintained] - A comprehensive JSON Schema validator for Node.js
BSD 3-Clause "New" or "Revised" License
217 stars 22 forks source link

TypeError: Cannot convert undefined or null to object #60

Open sshaw opened 8 years ago

sshaw commented 8 years ago
~/code/java/raml-test >jayschema json/request_address_correction.json schema/request_address_correction.schema.json
/usr/local/lib/node_modules/jayschema/lib/schemaRegistry.js:59
    if (!Object.prototype.hasOwnProperty.call(currentSchema, element)) {
                                         ^
TypeError: Cannot convert undefined or null to object
    at hasOwnProperty (native)
    at Function.SchemaRegistry._resolveJsonPointer (/usr/local/lib/node_modules/jayschema/lib/schemaRegistry.js:59:42)
    at SchemaRegistry.get (/usr/local/lib/node_modules/jayschema/lib/schemaRegistry.js:257:29)
    at run (/usr/local/lib/node_modules/jayschema/lib/suites/draft-04/index.js:93:43)
    at module.exports (/usr/local/lib/node_modules/jayschema/lib/suites/draft-04/keywords/_propertiesImpl.js:44:30)
    at run (/usr/local/lib/node_modules/jayschema/lib/suites/draft-04/index.js:126:28)
    at JaySchema._validateImpl (/usr/local/lib/node_modules/jayschema/lib/jayschema.js:227:10)
    at JaySchema.validate (/usr/local/lib/node_modules/jayschema/lib/jayschema.js:294:29)
    at Object.<anonymous> (/usr/local/lib/node_modules/jayschema/bin/validate.js:66:17)
    at Module._compile (module.js:460:26)

Looks like it's caused by a $ref with a filename. Here's the schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "foo",
    "type": "object",
    "properties": {
    "order_id": { "type": "integer" },
    "shipping_address": { "$ref": "definitions.json#/address" }
    },
    "additionalProperties": false
}

When "definitions.json" is removed the error is gone, but the $ref cannot be found.

loganrw commented 7 years ago

Same problem here. Has there been a work around in the time since this post?