-
Notifications
You must be signed in to change notification settings - Fork 151
Description
Discussed previously in #124 and #601 (comment)
At the moment, the schemas that we support all come from the YAML spec, and specify generic types that may exist in a document. This means that for plain nodes in particular, implicit tags are assigned to values based on regexp pattern matches.
As a possible alternative, we could support something like JSON Schema instead, which would allow for defining a document-specific structural schema, which would permit for much greater type safety in our output.
This would make it so that you could parse a YAML doc like
a: true
b: truewith an attached JSON schema
{
"type": "object",
"properties": {
"a": { "type": "string" },
"b": { "type": "boolean" }
}
}and end up with
{ a: 'true', b: true }but I've not been able to find a sensible way of making that happen.
I would much rather not write yet another JSON schema library, but the few times I've looked, I've found that all of them iterate on the schema rules in order to find any errors in the input data. That doesn't really work well here, as some process is needed that can take the above data and figure out that a: true should result in a string, while b: true should result in a boolean.
For simple examples like this that's of course pretty easy, but JSON schema is pretty powerful, and gets complex rather fast, with multiple rules affecting a single node.