File: index.rst

package info (click to toggle)
referencing 0.36.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 376 kB
  • sloc: python: 2,618; makefile: 13
file content (50 lines) | stat: -rw-r--r-- 1,851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
An implementation-agnostic implementation of JSON reference resolution.

In other words, a way for e.g. JSON Schema tooling to resolve the :kw:`$ref` keywords across all drafts without needing to implement support themselves.

This library is meant for use both by implementers of JSON referencing-related tooling -- like JSON Schema implementations supporting the :kw:`$ref` keyword -- as well as by end-users using said implementations who wish to then configure sets of resources (like schemas) for use at runtime.

The simplest example of populating a registry (typically done by end-users) and then looking up a resource from it (typically done by something like a JSON Schema implementation) is:

.. testcode::

    from referencing import Registry, Resource
    import referencing.jsonschema

    schema = Resource.from_contents(  # Parse some contents into a 2020-12 JSON Schema
        {
            "$schema": "https://json-schema.org/draft/2020-12/schema",
            "$id": "urn:example:a-202012-schema",
            "$defs": {
                "nonNegativeInteger": {
                    "$anchor": "nonNegativeInteger",
                    "type": "integer",
                    "minimum": 0,
                },
            },
        }
    )
    registry = schema @ Registry()  # Add the resource to a new registry

    # From here forward, this would usually be done within a library wrapping this one,
    # like a JSON Schema implementation
    resolver = registry.resolver()
    resolved = resolver.lookup("urn:example:a-202012-schema#nonNegativeInteger")
    assert resolved.contents == {
        "$anchor": "nonNegativeInteger",
        "type": "integer",
        "minimum": 0,
    }

For fuller details, see the `intro`.


.. toctree::
    :glob:
    :hidden:

    intro
    schema-packages
    compatibility
    api
    changes