w3c-ccg / traceability-vocab

A traceability vocabulary for describing relevant Verifiable Credentials and their contents.
https://w3id.org/traceability
Other
34 stars 35 forks source link

JSON Schemas can't be referenced by AJV due to non-standard HTTPS $schema URI #219

Closed tobek closed 2 years ago

tobek commented 3 years ago

The common Ajv library errors when referencing traceability JSON Schemas, since they use a different URI from the Draft 7 meta-schema URI for the $schema property (HTTPS "https://json-schema.org/draft-07/schema#" vs draft's HTTP "http://json-schema.org/draft-07/schema#"). Ajv doesn't recognize the schema due to the different URI, so it attempts to fetch it, and retrieves and processes the schema, whose ID is the standard HTTP URI, and when it attempts to cache this schema it throws schema with key or id "http://json-schema.org/draft-07/schema" already exists, since Ajv bundles the meta-schema automatically.

Example code to reproduce the error: https://codepen.io/tobek/pen/zYdyOgO?editors=0011

As of the 2019-09 JSON Schema draft, all meta-schema URIs use HTTPS, but older schemas (such as Draft 7 used by this repo) use HTTP for the canonical URI, so the solution would be either to use that canonical URI, or use a later draft if HTTPS is desired. I'm happy to make the update either way.

OR13 commented 2 years ago

This will change with YAML, but we expect to still be able to validate an instance against a schema that is identified with a URL.

OR13 commented 2 years ago

See https://github.com/w3c-ccg/traceability-vocab/pull/220

After it is merged we expect this to be solved in a different way, but still functional.

mprorock commented 2 years ago

+1 agree strongly that this should get addressed, but seems like we want to go revist post pr cutting default over to YAML as noted by @OR13

OR13 commented 2 years ago

I think we solved this.

BenjaminMoe commented 2 years ago

Closing.