-
-
Notifications
You must be signed in to change notification settings - Fork 591
Support for other file formats in the CLI #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi! Thanks for the idea and offer -- So, I do this personally with remarshal. E.g. by running I am... not completely against having that more native (though yeah for me what I do already works quite OK), but I have reservations about "magic". It's easy (as anymarkup says itself) to have ambiguous say INI vs TOML, so it's introducing room for complexity and incorrectness there. Happy to hear your thoughts on that if you have any. |
(not OP) I would be happy to have this for only yaml to start with since it doesn't introduce ambiguity, schemas are much nicer to write in yaml (and our own config files are in yaml and needs validation). Since yaml is a subset of json there shouldn't be much, if any, magic need :-) remarshal is a great tool, but your example is not quite so convenient on windows (or when both schema and instance are yaml). |
That all makes sense to me! Definitely OK with that much. |
@julesjulian I was looking to create a YAML linter that would use data from http://schemastore.org/json/ (which applies to yaml too) but without having native support for yaml I am kinda stuck. Once this is covered, I can start implementing the tool which should be able to detect schema to use, use internal cache of schemas, lint all files from a repo. If you think that this could be desirable for your tool, I don't mind extending it, otherwise I would make another tool that only calls jsonschema for validating the these files. |
@ssbarnea that's.. interesting, I don't think I'd seen that before. I think I'm not opposed to adding support for that if it's reasonably small to implement. Can we tackle that separately though? I.e., one ticket (this one) for just switching to parsing via YAML, and a second one for adding support for schema store to the CLI? |
I would be interested in having a transparent yaml loader with $ref resolution. It would require to restrict to the YAML syntax that is 1:1 transposable to json. |
"JSON Schema" schemas are not only written in JSON but also in YAML, a popular example is the Linux Kernel[0]. While it is possible to convert any input file from YAML to JSON on the fly[1], the automatic resolving of schema references is not possible. To allow YAML files for the CLI tool of jsonschema, check the file suffix and parse the referenced file as YAML if it ends on `yaml` or `yml`. In case the Python library `pyyaml` is not installed or any other suffix is found, parsing defaults to JSON as before. [0]: https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings [1]: python-jsonschema#582 (comment) Signed-off-by: Paul Spooren <[email protected]>
"JSON Schema" schemas are not only written in JSON but also in YAML, a popular example is the Linux Kernel[0]. While it is possible to convert any input file from YAML to JSON on the fly[1], the automatic resolving of schema references is not possible. To allow YAML files for the CLI tool of jsonschema, check the file suffix and parse the referenced file as YAML if it ends on `yaml` or `yml`. In case the Python library `pyyaml` is not installed or any other suffix is found, parsing defaults to JSON as before. [0]: https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings [1]: python-jsonschema#582 (comment) Signed-off-by: Paul Spooren <[email protected]>
"JSON Schema" schemas are not only written in JSON but also in YAML, a popular example is the Linux Kernel[0]. While it is possible to convert any input file from YAML to JSON on the fly[1], the automatic resolving of schema references is not possible. To allow YAML files for the CLI tool of jsonschema, check the file suffix and parse the referenced file as YAML if it ends on `yaml` or `yml`. In case the Python library `pyyaml` is not installed or any other suffix is found, parsing defaults to JSON as before. [0]: https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings [1]: python-jsonschema#582 (comment) Signed-off-by: Paul Spooren <[email protected]>
"JSON Schema" schemas are not only written in JSON but also in YAML, a popular example is the Linux Kernel[0]. While it is possible to convert any input file from YAML to JSON on the fly[1], the automatic resolving of schema references is not possible. To allow YAML files for the CLI tool of jsonschema, check the file suffix and parse the referenced file as YAML if it ends on `yaml` or `yml`. In case the Python library `pyyaml` is not installed or any other suffix is found, parsing defaults to JSON as before. [0]: https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings [1]: python-jsonschema#582 (comment) Signed-off-by: Paul Spooren <[email protected]>
"JSON Schema" schemas are not only written in JSON but also in YAML, a popular example is the Linux Kernel[0]. While it is possible to convert any input file from YAML to JSON on the fly[1], the automatic resolving of schema references is not possible. To allow YAML files for the CLI tool of jsonschema, check the file suffix and parse the referenced file as YAML if it ends on `yaml` or `yml`. In case the Python library `pyyaml` is not installed or any other suffix is found, parsing defaults to JSON as before. [0]: https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings [1]: python-jsonschema#582 (comment) Signed-off-by: Paul Spooren <[email protected]>
"JSON Schema" schemas are not only written in JSON but also in YAML, a popular example is the Linux Kernel[0]. While it is possible to convert any input file from YAML to JSON on the fly[1], the automatic resolving of schema references is not possible. To allow YAML files for the CLI tool of jsonschema, check the file suffix and parse the referenced file as YAML if it ends on `yaml` or `yml`. In case the Python library `pyyaml` is not installed or any other suffix is found, parsing defaults to JSON as before. [0]: https://github.com/torvalds/linux/tree/master/Documentation/devicetree/bindings [1]: python-jsonschema#582 (comment) Signed-off-by: Paul Spooren <[email protected]>
I think that for start trying using the pyyaml loader when file extension is either We could even make the dependency on pyyaml soft and enable the feature only when it is installed. |
While I'm not sure of the "anymarkup", given that YAML is widely used when developing json-schema and OpenAPI3 files, even a simple YAML loader (eg. yaml.safe_load) would be great. I think that a conservative solution could even rely on a specify CLI parameter (eg. --yaml) that will do something like
Probably a way to specify the loader in a single place could work too (eg. outputter.schema_loader ) If you are interested, I'm happy to PR :) |
Providing this feature is one of the main goals for It provides YAML for schema files is only supported for local files. Because a RefResolver won't understand YAML, it didn't seem very safe to try to load remote schemas as YAML. I'm happy to revisit or discuss this behavior. I'd love to hear from any of the users in this thread if I am the author of |
We're going to move forward and begin calling |
0015d5242 Merge pull request #583 from santhosh-tekuri/defs e14c68bb4 Replace '$defs' with 'definitions' in drafts 6,7 c4341bd0a Merge pull request #582 from santhosh-tekuri/defs 4ae2c9b93 Replace '$defs' with 'definitions' in draft 6,7 git-subtree-dir: json git-subtree-split: 0015d5242d146248cb47850a08012b4829462d3b
Would you consider adding support for validating other file formats (YAML, TOML, INI, etc) via JSON Schema? This would be similar to the functionality provided by this NodeJS project:
https://github.com/json-schema-everywhere/pajv
It is possible to add this functionality via the "anymarkup" module:
https://github.com/bkabrda/anymarkup
I can provide a pull request with these changes
The text was updated successfully, but these errors were encountered: