DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Reccommend replacing `jsonschema` crate with `boon` for improved JSON Schema support

Open michaeltlombardi opened this issue 2 years ago • 0 comments

Summary of the new feature / enhancement

The DSC libraries and tools implemented in rust currently use the jsonschema v0.17.0 crate for their JSON Schema handling. However, this implementation only fully supports JSON Schema drafts 4-7. Support for 2019-09 and 2020-12 is only partial and requires enabling a feature. Further, according to the official test suite maintained and published in collaboration with the JSON Schema team and community, jsonschema currently has six errors and 17 invalid results from the test cases.

By contrast, the boon v0.5.0 crate has full support for JSON Schema drafts 4-7, as well as 2019-09 and 2020-12. That version successfully passes every test case for the supported dialects.

Migrating from the jsonschema crate to boon would make the JSON Schema validation and integration more reliable and enable us to fully use draft 2020-12 JSON Schemas, which have several authoring improvements over prior drafts and are much easier to extend. Further, boon has support for custom assertions of formats, content media types, and content encoding, all of which would be useful for DSC:

https://github.com/santhosh-tekuri/boon/blob/d466730e5e5c7c663bd6739e74e39d1e2f7baae4/tests/examples.rs#L64-L92

That being said, it looks like the schemars v0.8.12 crate doesn't support 2020-12 yet, though it does support 2019-09. The largest differences between JSON Schema draft 2019-09 and 2020-12 are:

  • 2020-12 replaces items/additionalItems with prefixItems/items - this applies mostly to how you represent tuples - when items is an object instead of an array, the behavior is consistent for both dialects.
  • 2020-12 replaces $recursiveRef/$recursiveAnchor with $dynamicRef/$dynamicAnchor - neither of which we seem to use in our current schemas, but which has a large impact on defining custom vocabularies, which we may find desirable in the future.
  • 2020-12 updates the interactive behavior for the contains and unevaluatedItems keywords, but we don't use contains.

For our purposes, that means that exporting our schemas in the 2019-09 dialect will have no noticeable impact vs 2020-12.

Proposed technical implementation details (optional)

Migrate dependency/usage in the rust code for the various projects from jsonschema v0.17.0 to boon v0.5.0.

After migration: consider exporting schemas in the draft 2019-09 dialect instead of the draft 7 dialect.

michaeltlombardi avatar Jul 01 '23 14:07 michaeltlombardi