File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ class Specification(Generic[D]):
22
22
behavior across JSON Schema specification versions, etc.
23
23
"""
24
24
25
+ #: A short human-readable name for the specification, used for debugging.
26
+ name : str
27
+
25
28
#: Find the ID of a given document.
26
29
id_of : Callable [[D ], URI | None ]
27
30
@@ -33,6 +36,9 @@ class Specification(Generic[D]):
33
36
#: nor internal identifiers.
34
37
OPAQUE : ClassVar [Specification [Any ]]
35
38
39
+ def __repr__ (self ):
40
+ return f"<Specification name={ self .name !r} >"
41
+
36
42
def create_resource (self , contents : D ) -> Resource [D ]:
37
43
"""
38
44
Create a resource which is interpreted using this specification.
@@ -41,6 +47,7 @@ def create_resource(self, contents: D) -> Resource[D]:
41
47
42
48
43
49
Specification .OPAQUE = Specification (
50
+ name = "opaque" ,
44
51
id_of = lambda contents : None ,
45
52
subresources_of = lambda contents : [],
46
53
)
Original file line number Diff line number Diff line change @@ -56,26 +56,32 @@ def subresources_of(resource: ObjectSchema) -> Iterable[ObjectSchema]:
56
56
57
57
58
58
DRAFT202012 = Specification (
59
+ name = "draft2020-12" ,
59
60
id_of = _dollar_id ,
60
61
subresources_of = lambda contents : [],
61
62
)
62
63
DRAFT201909 = Specification (
64
+ name = "draft2019-09" ,
63
65
id_of = _dollar_id ,
64
66
subresources_of = lambda contents : [],
65
67
)
66
68
DRAFT7 = Specification (
69
+ name = "draft-07" ,
67
70
id_of = _dollar_id ,
68
71
subresources_of = _subresources_of (values = {"if" , "then" , "else" }),
69
72
)
70
73
DRAFT6 = Specification (
74
+ name = "draft-06" ,
71
75
id_of = _dollar_id ,
72
76
subresources_of = lambda contents : [],
73
77
)
74
78
DRAFT4 = Specification (
79
+ name = "draft-04" ,
75
80
id_of = _legacy_id ,
76
81
subresources_of = lambda contents : [],
77
82
)
78
83
DRAFT3 = Specification (
84
+ name = "draft-03" ,
79
85
id_of = _legacy_id ,
80
86
subresources_of = lambda contents : [],
81
87
)
Original file line number Diff line number Diff line change 4
4
from referencing .jsonschema import DRAFT202012
5
5
6
6
ID_AND_CHILDREN = Specification (
7
+ name = "id-and-children" ,
7
8
id_of = lambda contents : contents .get ("ID" ),
8
9
subresources_of = lambda contents : contents .get ("children" , []),
9
10
)
@@ -274,6 +275,7 @@ def test_from_contents_with_fallback(self):
274
275
275
276
def test_id_delegates_to_specification (self ):
276
277
specification = Specification (
278
+ name = "" ,
277
279
id_of = lambda contents : "urn:fixedID" ,
278
280
subresources_of = lambda contents : [],
279
281
)
@@ -367,6 +369,7 @@ def test_lookup_non_existent_pointer_to_array_index(self):
367
369
class TestSpecification :
368
370
def test_create_resource (self ):
369
371
specification = Specification (
372
+ name = "" ,
370
373
id_of = lambda contents : "urn:fixedID" ,
371
374
subresources_of = lambda contents : [],
372
375
)
@@ -377,6 +380,11 @@ def test_create_resource(self):
377
380
)
378
381
assert resource .id () == "urn:fixedID"
379
382
383
+ def test_repr (self ):
384
+ assert (
385
+ repr (ID_AND_CHILDREN ) == "<Specification name='id-and-children'>"
386
+ )
387
+
380
388
381
389
class TestOpaqueSpecification :
382
390
You can’t perform that action at this time.
0 commit comments