quicktype
quicktype copied to clipboard
Unhelpful error message when schema JSON is invalid
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/foo",
"definitions": {
"foo": {
"type": "object",
"properties": {
"bar": {
"$ref": "bar.json#"
},
},
"required": [
"bar"
],
},
"title": "foo"
}
}
Running quicktype CLI with this Schema produces
Error: Internal error: Defined value expected, but got undefined.
Let me see how I can help.
I tried running the above schema with quick type. On my machine it gives a helpful message. To be exact it outputs :
$ quicktype test.json
Error: Syntax error in input JSON test: Parser cannot parse input: unexpected token '}'.
I think that is pretty valid output. Though providing the line number and column will be pretty good
Well, this just cost me an entire day of debugging. 🤦♂️
For me, the problem was simply malformed CLI arguments combined with missing validation and poor error-reporting.
Might I propose, as an interim fix, we simply make the CLI print out it's configuration options before starting?
That way, we can at least tell if it's trying to do what we're trying to ask for.
My head hurts.
I am able to trigger this error message using relative references that quicktype is unable to look up:
Schema 1 with "$id":"myschema/definitions/base"
Schema 2 with "$id":"myschema/objects/foo"
and using "$ref":"../definitions/base"
If I understand the spec correctly, the $id should set the base URL of the schema, allowing for $ref to be relative. Not sure if quicktype does not follow the ".." part of the URL correctly, or if it is invalid, but the error message is triggered, and in this context, sensible. It should however provide the line number.