kdl
kdl copied to clipboard
KDL Schema spec clarifications/typos
I've been working through implementing a KDL Schema Validator, and I've run into a few questions. I will probably find more over time but this is what I have so far.
TYPOS
- ✅ "one info node for that describes the schema itself."
- ✅ there is a format "irl" (iri?)
- ✅ there is a format "irl-reference" (iri-reference?)
ERRORS / QUESTIONS
- ✅ does "zero or more..." imply optionality? Yes?
- ⁉️ node.children.tag: suggests it's mandatory and multiple, but schema-schema says 0 or 1?
- ❓ prop.children.required: fails to specify default value (true?)
- ❌ can
enumvalidations be an empty list? (implying nothing matches?)- ✅ I will make the docs clarify that they must have values
- ❓ what are the possible values for
typevalidations? (are these core types like "string" or rich types like "(i32)"? - ✅ the
nodenode has "zero or morechildren" but thechildrennode is itself a list of children..?- ✅ should just be "optional"
- ❓ the "defintions" node should be able to have multiple
childrenthough?
- ✅
%is... problematic with floating point. There are ways to do it, the rust json-schema crate handles it, but want to confirm this pandora's box is intentional.- ✅ zkat proposes dropping
multipleto avoid the question
- ✅ zkat proposes dropping
- Yes you're correct about the typos
- 0+ means optional, but potentially many, yes.
- uhhhh... idk and I'm confused and something doesn't seem right here
- the spec should probably be more specific about this, but schema-schema says "1+" and I think that's the right thing to do
- I think this was meant to be the core types? Sorry, it's been a while. What should it be?
- lol yes, that should probably be "optional"
- you're right. idk what to do about it. We could just scrap it for now because of its implications with floats? Since KDL doesn't really distinguish between float/non-float as far as numbers go.
Dope, I'll file a PR for some of these when I have better clarity on them. Some more issues:
ISSUES
- ❓ schema-schema: creative commons link missing its "rel" (documentation?)
- ❓ node.tag: "Validations to apply to the tag of the node." -- shouldn't this be a
tagnode? (schema-schema says so)
I AM CONFUSED
- ❓
tagnode: "The tag describes the tags allowed in a children block or toplevel document."childrennode doesn't use this- ❓ why does this exist / is this different from the
childrennode? or thenodenode? - ok wait in the schema-schema
childrendoes havetagby virtue of inheriting all ofdocument's nodes (withref)- but that also that grabs a pile of random crap it shouldn't (at very least
info) - ❓ was
infoanddefinitionssupposed to be not-under-the-document-node so that this kind of recursive definition would work? - ❓ or was
documentsupposed to havechildren? - ❓ actually maybe this inheritance works if it's inverted.
documentref's in the contents ofchildren?
- but that also that grabs a pile of random crap it shouldn't (at very least
- ❓ what is the meaning/purpose of
relin a url?- ❓ self?
- ❓ documentation?
On ref and id:
- ❓ completely overlays the matched node onto this node
- ❓ ...including
id? that seems... wrong.
- ❓ ...including
- ❓ replaces conflicts
- ❓ does this only apply to positional values?
- ❓ kdl technically supports conflicting copies of key=val, but in a way that is basically an overlay so it's moot..?
- ❓ you can always have multiple copies of a node with a given name, so unclear how conflicts could be defined
- ❓ I guess meaningful for nodes that are "at most 1"?
- ❓ is the behaviour of
refconsistent across all node types?- ❓ wording varies, unclear if the net effect is always the same
- ❓ should it be required that the source and target are the same kind of node?
- ❓ i.e. should
valuesonly be allowed to importvalues? - currently I guess not, schema-schema puns
documentandchildren
- ❓ i.e. should
- ❓ what should happen if there are multiple matches?
- ❓ error? (yes please)
- ❓ merge? (god no)
- ❓ are ids really global, or per-node-kind?
- ❓ what happens if ids aren't globally unique? error?
- ❓ this can't be expressed in the schema-schema, should it?
- ❓ ref is defined to be an arbitrary KQL string but it's unclear if there's any practical application of anything but
[id="blah"]- not needing to support all of KQL as a subsystem would be... much easier
updated my formatting a bit so it's easier to refer to specific points and I can keep track of where my understanding is
On Schema Referencing
(This is future-facing stuff, not necessarily problems in the current spec)
-
❓ There is currently no way for a schema to specify what schema-schema it follows
- ❓ or equivalently, what version of the KDL Schema Spec it follows
- ❓i think there should be a top-level
kdl-schemanode to this effect (see point 2 below for why not ininfo) - ❓ json-schema has a
"$schema": "https://..."key for this purpose- Using a URL to specify the version is interesting... mixed on it.
- In principle it allows a modicum of forward-compat... except a new schema-schema would presumably be self-referential
- If you did specify a schema-schema in the syntax of an older schema-schema, you...
- would be able to validate schemas using the new schema-schema for correctness (assuming all constraints of interested could be encoded in the schema-schema, which is not the case with things like
iduniqueness) - wouldn't be able to use those schemas because we still wouldn't understand the semantics
- could assume the schema is essentially the same but just includes modular things like new
validationsand proceed while ignoring things we don't understand (more on this in a subsequent comment)
- would be able to validate schemas using the new schema-schema for correctness (assuming all constraints of interested could be encoded in the schema-schema, which is not the case with things like
-
❓Microsoft has a non-standard extension/convention that any JSON that has a top-level
"$schema": "https://..."key will be validated against that schema- love this, means weirdo formats can immediately get IDE support if the KDL Language Server supports this
- it also supports querying https://www.schemastore.org/json/ based on file name or something? works well for things like
package.jsonorCargo.toml
On forward-compat / extensibility
(This is future-facing stuff, not necessarily problems in the current spec)
Forward-compat and extensibility are two sides of the same coin: to what extent can things be designed to support New Or Non-Standard Features. However all the defaults of the KDL Schema seem tuned heavily against this. In particular (unlike json-schema) everything defaults to "only what I've mentioned is allowed". I get the inclination but it's pretty hazardous to the goals of this section.
In my prototype I've identified a few places where extensibility could be supported:
- If a node has "all validations" in its children set I parse all unknown node kinds as
Validation::Unknown(KdlNode)and assume I will provide some kind of hook for custom validators - similarly there is
Validation::UnknownFormat(String)forformat "???" - I don't currently do this for
link rel="???", maybe I should
Features that would be useful for forward-compat:
- default values for optional things
- makes the schema more like documentation
- potentially allows applications to apply the defaults
- potentially allows future schemas with more complex rules to "bootstrap" semantics with actual values
- ability to declare an
enumas open/non-exhaustive- arguably useless in a vacuum (would negate the entire function), but if
enumvalues could include descriptions this would again gain more documentation (IDE tooltips!) - hmm or at this point should you just be using the proper
valuesnode? wait no eachvaluesentry is just specifying min/max len and then deferring to validations...
- arguably useless in a vacuum (would negate the entire function), but if