raml-js-parser icon indicating copy to clipboard operation
raml-js-parser copied to clipboard

Error in parsing nested json schemas

Open AFactor opened this issue 10 years ago • 6 comments

Raml parser doesn't attempt to parse or validate the nested schema. { "required": true, "description": "Bulk buy limit attributes", "type": [ "object", "null" ], "$ref": "bulkbuy-schema.json"
} In the following example it would just treat this as a text. The fact that $ref is there wouldn't mean anything to RAML parser.

AFactor avatar Nov 24 '14 22:11 AFactor

I'm seeing this problem as well. When running raml.loadFile on the raml file found at:

https://github.com/mulesoft/api-console/blob/master/app/examples/github.raml

Most of the embedded post body schemas are being evaluated as text.

ty10r avatar Dec 02 '14 07:12 ty10r

Hi, yes this is an open req for the parser: validation of JSON schemas.

If you guys are aware of a good js library that does JSON schema validation (not only validations of JS objects against a JSON schema) and handles these, we could include it in an updated version of the parser.

dmartinezg avatar Dec 02 '14 11:12 dmartinezg

@dmartinezg this looks to be relatively clean, and active. https://github.com/geraintluff/tv4

naterkane avatar Dec 02 '14 18:12 naterkane

@naterkane correct that is a good library to validate JS objects against a schema, that parser however does not really validate JSON schemas against the JSON schema spec, I just tried this:

var tv4 = require('tv4');
var valid = tv4.validate({}, {'foo': false});
console.log(valid);

and it outputs: true, am I wrong?

dmartinezg avatar Dec 02 '14 18:12 dmartinezg

@dmartinezg Okay a few things. First when you say that tv4 lets you validate objects against a schema but not schemas against the spec; that is wrong. In fact there is no difference between the 2 operations because a schema is a json object and the spec is a json schema. So tv4 can accomplish this. It's just not easy :frowning: .

The biggest problem I've found with tv4 is that any references to other schemas (via the $schema or $ref keywords) must be pre-loaded before attempting to validate. This is a pain.

Here is an example repo to demonstrate my point: https://github.com/thebinarypenguin/tv4-sandbox

So while I don't have a ready solution tv4 can probably be used to create one.

thebinarypenguin avatar Dec 30 '14 02:12 thebinarypenguin

Maybe this project might be worth looking into for dereferencing $ref properties? bojand/json-schema-deref-sync.

schmkr avatar May 27 '15 07:05 schmkr