jerg
jerg copied to clipboard
Incorrect `extends` handling
According to http://tools.ietf.org/html/draft-zyp-json-schema-03#page-14 extends field could be or scheme (aka JSON object) or array of schemas (JSON array).
this example will illustrate error: api.json:
{
"type" : "object",
"extends" : [
{"$ref" : "rq.json"},
{
"properties" : {
"id" : {
"type" : "integer",
"required" : true
}
}
}
]
}
rq.json:
{
"abstract" : "true",
"type" : "object",
"properties" : {
"type" : {
"type" : "string",
"maxLength" : "10",
"minLength" : "2"
}
}
}
Result:
$ jerg -s . -t -
escript: exception error: no match of right hand side value false
in function jerg:get_schema/2 (src/jerg.erl, line 158)
in call from jerg:collect_properties/2 (src/jerg.erl, line 334)
in call from jerg:output_properties/3 (src/jerg.erl, line 283)
in call from jerg:output_object_record/4 (src/jerg.erl, line 262)
in call from jerg:output_records/3 (src/jerg.erl, line 245)
in call from jerg:run/1 (src/jerg.erl, line 88)
in call from jerg:main/1 (src/jerg.erl, line 34)
I trace down a problem, looks like kvc issue.
This is JsonSchema from here https://github.com/ddossot/jerg/blob/master/src/jerg.erl#L329
[{<<"type">>,<<"object">>},
{<<"extends">>,
[[{<<"$ref">>,<<"rq.json">>}],
[{<<"properties">>,
[{<<"id">>,
[{<<"type">>,<<"integer">>},{<<"required">>,true}]}]}]]}]
And result of https://github.com/ddossot/jerg/blob/master/src/jerg.erl#L330 will be [<<"rq.json">>] instead of <<"rq.json">>.
true = [a, b, c] == kvc:path([extends, '$ref'], [{extends, [ [{'$ref', a}], [{'$ref', b}], [{'$ref', c}] ]}]).