strictyaml
strictyaml copied to clipboard
Language independent schema
Hi, Now, StrictYAML use Python code for defining schema of a data, but for beeing popular and wide used StrictYAML must have possibility to be ported to other languages. Maybe will be good if data schema will be YAML/StrictYAML?
Addition: not just for porting, but for reusing schema between languages.
Hi @worldmind
I have a documentation page on why I don't define schemas in YAML : https://hitchdev.com/strictyaml/why/turing-complete-schema/
I do think that the base should be ported to other languages - the ability to parse mappings, sequences and strings (multiline and single line) but I'd be happy to see other languages implement their own schema language - or even not have a schema at all (strictyaml technically doesn't need a schema).
As far as I'm concerned the "data format" of StrictYAML and the schema validation are entirely separate entities. The former is very simple (kind of like JSON) while the latter is pretty complex and evolving and probably won't translate all that well away from python.
I also think that it's a good idea to make a jsonschema -> StrictYAML validator converter (the other way is not possible). I started a project last year where you could input a jsonschema and get a valid strictyaml schema object out ( https://github.com/hitchdev/strictyamljsonschema ) but I lost steam - partly because I don't have a use for such a thing myself. I'd love to see it exist, to aid it and promote it though.
Yes, JSONSchema it's a beautiful way.
probably won't translate all that well away from python
Maybe I misunderstood something, you says that some data structures can't be implemented in other languages?
No, I think that they can but I can't see a way of creating a language independent schema without sacrificing flexibility and/or strictness. For instance in strictyaml you can:
- Revalidate whole portions of the document based upon what is in other portions of the document (there's an example of this in the revalidation docs).
- Easily pull in external data (e.g. a frequently updated list of country codes, time zones and international dial codes) from externally managed sources and use them to validate.
- Create custom validators that use custom logic - e.g. create a Hong Kong ID card validator based upon the standard ID card validation algorithm.
- Create a custom validator/typecaster that uses the python-slugify package (I use this one a lot).
A framework to do all of this requires the validation to be done with turing complete code. It's basically not possible with JSON schema (at least, not without using nasty hacks).
Personally I have found the above kind of flexibility to be absolutely vital for the purposes I have used strictyaml for while portability of schemas across programming languages simply isn't a requirement I've ever had.
You could duplicate the way it's done in some other languages and so the schemas look very similar (and perhaps share names - like map and mappattern) but they'd still look substantially different in the end.
If other languages do implement their own version of strictyaml (and I very much hope that they do) I'd ideally like to see them follow a similar pattern for similar reasons. Turing complete schemas are underrated IMHO. I'd be somewhat less fussed about them being consistent with strictyaml (e.g. if the javascript version had a MapPattern but called it something else I think that'd be okay).
Thank for explanation, sorry I miss https://hitchdev.com/strictyaml/why/turing-complete-schema/ I suppose that will be great if you make link to this page from main page for example by adding new item in priorities list, may be something like "Data schema is Python code because flexibility is matter, details here".