jsonschema-rs icon indicating copy to clipboard operation
jsonschema-rs copied to clipboard

Implement Draft 2019-09

Open Stranger6667 opened this issue 5 years ago • 9 comments

Validation docs: https://tools.ietf.org/html/draft-handrews-json-schema-validation-02

New keywords:

  • [x] $anchor
  • [x] $definitions
  • [x] $recursiveRef
  • [x] $recursiveAnchor
  • [ ] #287
  • [x] #288
  • [x] contentSchema
  • [x] maxContains
  • [x] minContains
  • [x] deprecated
  • [x] #286 (instead of dependencies)

Implementation examples - TypeScript, Python (partial)

Stranger6667 avatar May 14 '20 18:05 Stranger6667

Looking forward to have this available 🙂️

aexvir avatar Aug 28 '20 13:08 aexvir

Hope to get back to this feature soon :)

Stranger6667 avatar Aug 30 '20 17:08 Stranger6667

Now there's Draft 2020-12

fimbault avatar Mar 26 '21 10:03 fimbault

We should be able to implement both 2019-09 and 2020-12 in one go I think. Here's my understanding of the work to be done:

Work to be done

Based on the changes from Draft-07 to 2019-09

Annotations, errors and outputs

  • Implement collection of annotations whilst evaluating schemas
  • Implement the "basic" output format to provide access to collected annotations

Core vocabulary changes

  • Split the various keywords into different vocabularies and implement processing of the $vocabulary keyword to determine which keywords are available to a schema
  • Implement $anchor keyword
  • Disallow use of fragments in $id (that usecase being taken up by $anchor)
  • Implement $definitions keyword
  • Implement $recursiveRef and $recursiveAnchor (these are renamed to $dynamicRef and $dynamicAnchor in 2020-12 but the latter is a superset of the former so we can use the same implementation)

Applicator Vocabulary

  • Split dependencies into dependentSchemas and dependentRequired
  • Implement unevaluatedItems and unevaluatedProperties

Format changes

  • Add an option to turn off processing of the format keyword and instead merely make it available as an annotation
  • Implement the duration and uuid format validators
  • Make contentEncoding available as an annotation and not as an assertion
  • Implement the contentSchema keyword

Validation

  • Implement maxContains and minContains

Meta-data

  • Implement deprecated

Based on changes from 2019-09 to 2020-12

  • replace items and additionalItems with prefixItems and ites
  • implement $dynamicRef and $dynamicAnchor (see above re. $recursive* versions)

Common components

  • Ensure that items which pass a contains schema are not processed by an unevaluatedItems schema. This is not specified in 2019-09 but is compatible

alexjg avatar Jul 26 '21 11:07 alexjg

Great write-up, @alexjg !

I have some small bits here and there (maybe incomplete):

  • minContains & maxContains - https://github.com/Stranger6667/jsonschema-rs/commit/16b75185905faf5a5b15f0e76aaf9967838c3a76
  • depentRequired - https://github.com/Stranger6667/jsonschema-rs/commit/94105822894cd296783f8f7e4b28ec2a9a56576f

Here is also some existing (but not yet merged) implementation for needed keywords. It might help to implement those keywords here.

I like the plan and would be happy to split it into granular tasks! I'll also check it in more detail in a few days.

I think some changes could be done and merged, but we may not expose them (e.g. new keyword impls) until their respective drafts are ready. So, there should be no problem with accumulating changes step-by-step. Though, we can still test them high-level via some cfg(test) items - e.g. conditional Draft201909 enum variant.

What do you think if we approach the implementation this way?

Stranger6667 avatar Jul 26 '21 13:07 Stranger6667

That seems like a sensible way to proceed. I'm going to make a start on the annotation collection and output formatting part as that feels like it's the largest change architecturally.

alexjg avatar Jul 27 '21 13:07 alexjg

Great!

Here are separate issues for the entries above.

2019-09

Annotations, errors and outputs

  • https://github.com/Stranger6667/jsonschema-rs/issues/262
  • https://github.com/Stranger6667/jsonschema-rs/issues/100
  • https://github.com/Stranger6667/jsonschema-rs/issues/267

Core vocabulary changes

  • https://github.com/Stranger6667/jsonschema-rs/issues/263
  • https://github.com/Stranger6667/jsonschema-rs/issues/264

Format changes

  • https://github.com/Stranger6667/jsonschema-rs/issues/261
  • https://github.com/Stranger6667/jsonschema-rs/issues/265
  • https://github.com/Stranger6667/jsonschema-rs/issues/266

I added new keyword implementation as sub-tasks in existing issues for their relevant drafts (this one and #195 ).

Stranger6667 avatar Jul 27 '21 17:07 Stranger6667

I'll set up conditional compilation for testing & merge existing keywords implementation, so we can run tests & add new one easier. It should be pretty much isolated, so I hope we can avoid conflicting changes.

Stranger6667 avatar Jul 27 '21 17:07 Stranger6667