You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to write a YAML schema referencing another YAML schema [1].
This results in:
Failure resolving $ref within schema
RefResolutionError: Expecting value: line 1 column 1 (char 0)
in "/usr/local/lib/python3.8/dist-packages/check_jsonschema/checker.py", line 73
>>> errors = self._build_error_map()
caused by
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
in "/usr/local/lib/python3.8/dist-packages/jsonschema/validators.py", line 816
>>> document = self.resolve_remote(url)
caused by
StopIteration: 0
in "/usr/lib/python3.8/json/decoder.py", line 353
>>> obj, end = self.scan_once(s, idx)
caused by
KeyError: 'file:///path/to/B.schema.yml'
in "/usr/local/lib/python3.8/dist-packages/jsonschema/validators.py", line 813
>>> document = self.store[url]
It does make sense, as resolving the reference schema is handled by jsonschema, which has no support for YAML − took me a while to get there though :)
Hence I’m not sure whether much can be done in check-jsonschema (perhaps some documentation clarification and/or error message hint)
[1] Something along the lines of the following − exact syntax might be still be off as I’m still figuring things out ^_^
It does make sense, as resolving the reference schema is handled by jsonschema, which has no support for YAML − took me a while to get there though :)
Yep, you've understood what's happening.
This suggests to me that it might be in order for check-jsonschema to spit a warning out when loading a schema defined in YAML. Not everyone would be able to figure it out on their own.
I'll think about the appropriate behavior here more.
It is possible to customize how jsonschema loads schema references (see RefResolver.resolve_remote), but I'd rather not meddle with that stuff if possible.
I'm not hostile towards the use of YAML for schema definitions, but I don't think it's a great idea because you'll run into issues like this. After all, the spec is "JSON Schema", not YAML Schema. 😉
That said, I'll also think about whether or not support for local YAML schema references makes sense.
In the meantime, if you want multiple schemas as YAML with references, the best I can recommend is using a tool like remarshall to setup a worfklow that handles this.
Imagine
for x in schemas/*.yml; do yaml2json "$x" > "$x.json"; done
and write your schema to reference B.yml.json.
I'm leaving this open until at least I have a warning or other behavior to help people out in place.
$ref usage may now refer to YAML, TOML, or JSON5 files, or any other non-JSON format supported by check-jsonschema. The file type is inferred only from the file extension in these cases and defaults to JSON if there is no recognizable extension.
Hey there,
I have been trying to write a YAML schema referencing another YAML schema [1].
This results in:
It does make sense, as resolving the reference schema is handled by jsonschema, which has no support for YAML − took me a while to get there though :)
Hence I’m not sure whether much can be done in check-jsonschema (perhaps some documentation clarification and/or error message hint)
[1] Something along the lines of the following − exact syntax might be still be off as I’m still figuring things out ^_^
The text was updated successfully, but these errors were encountered: