Skip to content

Commit 9880c3d

Browse files
committed
Add a simple-ish example to the doc homepage.
Otherwise it's kind of bare. Closes: #39
1 parent 100ec83 commit 9880c3d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

docs/index.rst

+37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@ An implementation-agnostic implementation of JSON reference resolution.
22

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

5+
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.
6+
7+
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:
8+
9+
.. testcode::
10+
11+
from referencing import Registry, Resource
12+
import referencing.jsonschema
13+
14+
schema = Resource.from_contents( # Parse some contents into a 2020-12 JSON Schema
15+
{
16+
"$schema": "https://json-schema.org/draft/2020-12/schema",
17+
"$id": "urn:example:a-202012-schema",
18+
"$defs": {
19+
"nonNegativeInteger": {
20+
"$anchor": "nonNegativeInteger",
21+
"type": "integer",
22+
"minimum": 0,
23+
},
24+
},
25+
}
26+
)
27+
registry = schema @ Registry() # Add the resource to a new registry
28+
29+
# From here forward, this would usually be done within a library wrapping this one,
30+
# like a JSON Schema implementation
31+
resolver = registry.resolver()
32+
resolved = resolver.lookup("urn:example:a-202012-schema#nonNegativeInteger")
33+
assert resolved.contents == {
34+
"$anchor": "nonNegativeInteger",
35+
"type": "integer",
36+
"minimum": 0,
37+
}
38+
39+
For fuller details, see the `intro`.
40+
41+
542
.. toctree::
643
:glob:
744
:hidden:

docs/spelling-wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ deserialized
88
discoverability
99
docstrings
1010
filesystem
11+
implementers
1112
instantiable
1213
instantiation
1314
iterable

0 commit comments

Comments
 (0)