spec-tools icon indicating copy to clipboard operation
spec-tools copied to clipboard

JSON Schema output is missing the key $schema

Open miikka opened this issue 5 years ago • 2 comments

As pointed out in #205, the JSON Schema output does not have a top-level key "$schema". According to the draft-04 spec:

The "$schema" keyword is both used as a JSON Schema version identifier and the location of a resource which is itself a JSON Schema, which describes any schema written for this particular version.

This keyword MUST be located at the root of a JSON Schema. The value of this keyword MUST be a URI [RFC3986] and a valid JSON Reference [json-reference]; this URI MUST be both absolute and normalized. The resource located at this URI MUST successfully describe itself. It is RECOMMENDED that schema authors include this keyword in their schemas.

Since there are now multiple versions of JSON Schema in production use, it'd be wise to include "$schema" in spec-tools's output:

"$schema": "http://json-schema.org/draft-04/schema#"

miikka avatar Jan 14 '20 07:01 miikka

Hi! As you said in #205 the current implementation only honors the draft-04 contract therefore I thought of only adding a simple function like

(defn- add-schema-key
  "As discussed in issue #205 the new drafts are not backward-compatible.
  That said, we can only add this new key with the correct value as-is."
  [schema]
  (assoc schema :$schema "http://json-schema.org/draft-04/schema#"))

And call it in the same places where maybe-with-titles is used. Is that appropriate? I can open a new PR with this inclusion.

wandersoncferreira avatar Mar 25 '20 22:03 wandersoncferreira

That sounds like a good solution, a PR would be certainly welcome.

miikka avatar May 05 '20 19:05 miikka