Open renich opened 2 years ago
Ultimately this discussion needs to yield an answer to two question:
I suppose the best way forward for such a proposal is to start as a shard, and then if probed useful move it to stdlib. But definitively this can be a place to discuss a possible API.
Would there be any feasability of a common validation framework that could encompass features from a variety of data languages? I have just been trying to use the Json Schema shard without enormous success, although I tihkn half of this is that last time I worked with JSON schemata it was not pleasant, and seems to be a headachey system - the website examples did not work with the CLI tool I have downloaded.
Presumably, when serialising and deserealising from any language, there is a certain amount of common work - macros to generate classes, basic validation of values, some sort of parsing infrastructure. If possible, it might be nice to see some of this encapsulated in a common way, that can then be specified and tailored for different languages (JSON, YAML, XML, TOML, I don't know what else off the top of my head...).
Also an aside, but I have just come across TypeSchema trying to see if there's an alternative I could use more easily. NOt so relevant for XML, but supporting osmehting cross-language like this may be an interesting thing if someone wanted to pick it up.
Edit: Nicolab/crystal-validator seems to be doing something like this
Let me reword this slightly - in order to apply the DRY principle, when different document/data languages are serialised or deserialised, they are working around a common way to represent data in the language (classes and structs, or arrays and hashes, of course. We also have the macro system to support generating boilerplate at compile-time, and schema parsers can utilise this to generate their classes automatically). In parallel, I would like to see a common way of validating data within Crystal, and then, for validators specific to languages that crystal can serialise and deserialise to/from hook into that generic validation framework, in order that each language validator need then only tailor the generic features to the semantics of what that language is able to provide or requires.
I would like to see a common way of validating data within Crystal, and then, for validators specific to languages that crystal can serialise and deserialise to/from hook into that generic validation framework, in order that each language validator need then only tailor the generic features to the semantics of what that language is able to provide or requires.
By language do you mean format? Because I think there are few somewhat separate things being discussed:
JSON::Serializable
and YAML::Serializable
are intended for.Depending on how you're envisioning this to work, a forum thread (or at least a separate issue) might be a better starting point. As this one is purely focused on:
Given an XML string, how can I validate it with an existing XSD file
This is something that we're have been planning to use a binding to libxml2 for, in our application. It would be much nicer though, if it were as a shard or ultimately, built-in, for sure.
Discussion
What aspect of the language would you like to see improved? Currently, crystal cannot handle XSD validation via the XML module even, though, the libxml2 library can.
What are the reasons? I do not know.
Include practical examples to illustrate your points. In this conversation, @Blacksmoke16 created one: https://gitter.im/crystal-lang/crystal?at=62aa87774e38f759e2c0fe38
Optionally add one (or more) proposals to improve the current situation. I am sorry, I an not that code-savvy to be able to. Maybe the example @Blacksmoke16 created could be of help.