Hi all,
I've written a schema that I'm quite happy with. You can see it here
in YAML syntax:
https://gist.github.com/estan/a8f824d657c07203df4641610cae2aed
It's the first time I use JSON Schema, and I must say I really like it.
There's one thing that my schema really miss though, and that's
disallowing additional properties in most places.
The reason I haven't added this is because I'm using a construct like
allOf:
- type: object
properties:
# Properties common to all items
anyOf:
- type: object
properties:
# Properties for one type of item
- type: object
properties:
# Properties for another type of item
to express an is-a relationship (see the "specification" property in
the schema), which AFAICS makes it impossible to use
additionalProperties: false, since the "reach" of the
additionalProperties only extends to the lexical scope so to speak.
I've seen others having the same problem, but I've never seen any
satisfactory solution, so I thought I'd ask you experts: Is there any
way to solve this without going through hoops or violating DRY?
Suggestions I've seen are:
1. Simply live with repetition and ditch the allOf, and repeat
common properties in each item.
2. Simply give up and allow additional properties
3. Various restructurings of the schema that makes it less legible
and still having some repetition
I don't like 1 because it makes editing the schema error prone.
Number 2 would be an option, and normally I think I'd do this, but in
this case I really want to disallow additional properties. The reason
is this: The schema describes a specification for a file/tree
structure. These specifications are used as input for a validation
tool we use to validate data format of ours. If additional properties
are allowed, it's very easy for someone to change something in the
validation tool and forgetting to update all our specs. Data could
then still seemingly validate, but in fact be invalid, which would be
very bad.
Regarding number 3, I still haven't found a solution that expresses
what I mean as clearly as the above, that's kind of why I'm asking
here if anyone has found a good solution to this problem.
I know that v5 introduces some things that would solve this (merge?)
elegantly, but our tooling uses PyYAML, so I must stick to v4.
Many thanks in advance!
Elvis