You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are 3 main objects to be aware of in the `referencing` API:
25
+
26
+
* `referencing.Registry`, which represents a specific immutable set of JSON Schemas (either in-memory or retrievable)
27
+
* `referencing.Specification`, which represents a specific *version* of the JSON Schema specification, which can have differing referencing behavior.
28
+
JSON Schema-specific specifications live in the `referencing.jsonschema` module and are named like `referencing.jsonschema.DRAFT202012`.
29
+
* `referencing.Resource`, which represents a specific JSON Schema (often a Python `dict`) *along* with a specific `referencing.Specification` it is to be interpreted under.
30
+
31
+
As a concrete example, the simple schema ``{"type": "integer"}`` may be interpreted as a schema under either Draft 2020-12 or Draft 4 of the JSON Schema specification (amongst others); in draft 2020-12, the float ``2.0`` must be considered an integer, whereas in draft 4, it potentially is not.
32
+
If you mean the former (i.e. to associate this schema with draft 2020-12), you'd use ``referencing.Resource(contents={"type": "integer"}, specification=referencing.jsonschema.DRAFT202012)``, whereas for the latter you'd use `referencing.jsonschema.DRAFT4`.
33
+
34
+
.. seealso:: the JSON Schema :kw:`$schema` keyword
35
+
36
+
Which should generally be used to remove all ambiguity and identify *internally* to the schema what version it is written for.
37
+
38
+
A schema may be identified via one or more URIs, either because they contain an :kw:`$id` keyword (in suitable versions of the JSON Schema specification) which indicates their canonical URI, or simply because you wish to externally associate a URI with the schema, regardless of whether it contains an ``$id`` keyword.
39
+
You could add the aforementioned simple schema to a `referencing.Registry` by creating an empty registry and then identifying it via some URI:
`referencing.Registry` is an entirely immutable object.
56
+
All of its methods which add schemas (resources) to itself return *new* registry objects containing the added schemas.
57
+
58
+
You could also confirm your schema is in the registry if you'd like, via `referencing.Registry.contents`, which will show you the contents of a resource at a given URI:
@@ -244,7 +291,19 @@ Older versions of `jsonschema` used a different object -- `_RefResolver` -- for
244
291
245
292
If you are not already constructing your own `_RefResolver`, this change should be transparent to you (or even recognizably improved, as the point of the migration was to improve the quality of the referencing implementation and enable some new functionality).
246
293
247
-
If you *were* configuring your own `_RefResolver`, here's how to migrate to the newer APIs:
294
+
.. table:: Rough equivalence between `_RefResolver` and `referencing.Registry` APIs
0 commit comments