raml-js-parser
raml-js-parser copied to clipboard
Error in parsing nested json schemas
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.
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.
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 this looks to be relatively clean, and active. https://github.com/geraintluff/tv4
@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 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.
Maybe this project might be worth looking into for dereferencing $ref
properties?
bojand/json-schema-deref-sync.