Creating Third-Party Vocabs #510
Replies: 3 comments 5 replies
-
I might be missing something, but I can't tell of any advantage of Option 1 over Option 2, and vocabulary meta-schemas defining |
Beta Was this translation helpful? Give feedback.
-
I exists. I wrote it back in March 2021.
|
Beta Was this translation helpful? Give feedback.
-
I think either approach is fine depending on the dialect author's intended use. If your custom vocabulary is only intended to be used by your custom dialect, then putting them in the same schema is fine. However, the intention of a vocabulary is often for it to be shared and combined with other vocabularies. For that to work, you need a separate vocabulary schema. Let's assume I created a vocab with keyword So, the default should definitely be Option 1, but if the vocabulary is entirely private and used only in one dialect, Option 2 is fine too. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone. @jviotti and I have been discussing the proper way to make a third-party vocab. It seems that we've found two approaches, and we wanted to get others' opinions.
(In the process of writing this, I had some additional questions fall out. I've opened #511 for that so the topics don't get too muddled.)
Option 1
This option is based on the 2020-12 meta-schemas. Each vocabulary has its own meta-schema, then they're all combined into a 2020-12 dialect meta-schema.
A vocab spec - This is a document that defines the keywords both syntactically, semantically, and behaviorally. It includes the vocab identifier URI and a vocab meta-schema URI. It can also give a reason why they're needed, use cases, etc. The definition is the important part, though.
Vocab meta-schema - This is a meta-schema that only describes the vocab itself. It contains a $vocabulary keyword that only contains the vocab URI, and it doesn't directly reference the main (e.g. 2020-12) meta-schema (unless one of the other keywords is an applicator). Keywords are defined here with subschemas that it can enforce syntax.
Dialect meta-schema - This meta-schema actually extends another meta-schema (e.g. 2020-12) by incorporating all of its vocabularies plus the custom vocab. It then references (via
$ref
) the base meta-schema and the vocab meta-schema so that validation of all of the keywords can occur. Lastly, it defines $dynamicAnchor: meta so that dynamic references come back to this meta-schema.Option 2
The same as the above, except the vocab and dialect meta-schemas are combined. There's a single meta-schema that both extends the base meta-schema (2020-12 in this case) and defines syntax for the added keywords.
This is how I've done my
data
(link) anduniqueKeys
(link) vocabs. The distinction isn't that huge, but I feel that doing it this way saves having to write another document.I wrote mine a couple years ago, and to my knowledge the only other third-party vocab is OpenAPI's, and they didn't publish a meta-schema (I don't think).
It seems to me that Option 1 has an advantage over Option 2 in that the vocab meta-schema can be reused across multiple dialects (even across JSON Schema versions). That makes a lot of sense, except that the meta-schema itself still needs a meta-schema, which inevitably ends up being the current main JSON Schema meta-schema (e.g. 2020-12). Maybe that's not really a problem, though.
Beta Was this translation helpful? Give feedback.
All reactions