@@ -40,6 +40,63 @@ seen below.
40
40
41
41
.. autofunction :: replace_refs
42
42
43
+ The different modes
44
+ -------------------
45
+
46
+ ``proxies ``
47
+ ^^^^^^^^^^^
48
+
49
+ The default mode (``proxies=True ``) uses :class: `JsonRef ` proxy objects to replace the
50
+ reference objects in the document. For most purposes, they proxy everything to the
51
+ referenced document. This can be useful for a few reasons:
52
+
53
+ - The original reference object is still available with the
54
+ :attr: `JsonRef.__reference__ ` attribute.
55
+ - :func: `dump ` and :func: `dumps ` can be used to output the document again, with the
56
+ references still intact. (Including changes made.)
57
+
58
+ If you are using a tool that does not play nicely with the :class: `JsonRef ` proxy
59
+ objects, they can be turned off completely using ``proxies=False ``. This is needed e.g.
60
+ if you want to pass the data back to the stdlib :func: `json.dump ` function.
61
+
62
+ ``lazy_load `` and ``load_on_repr ``
63
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64
+
65
+ By default, the references will not actually be resolved until the data is accessed
66
+ (``lazy_load=True ``.) This can be useful to limit the upfront processing of deeply
67
+ nested, or otherwise complicated reference trees. To limit the lookups even more, the
68
+ ``load_on_repr `` argument can be set to ``False ``, so that printing the document will
69
+ not cause the references to load (this can be especially useful when debugging.) The
70
+ downside of this mode is that exceptions when a reference cannot be loaded might be
71
+ issued from more places when using the loaded document. Turning off lazy loading can
72
+ make catching errors much easier.
73
+
74
+ ``merge_props ``
75
+ ^^^^^^^^^^^^^^^
76
+
77
+ When using this mode, extra properties from the reference object will be merged into
78
+ the referenced document. e.g.::
79
+
80
+ >>> json = {
81
+ "a": {"$ref": "#/b", "extra": "blah"},
82
+ "b": {"real": "b"}
83
+ }
84
+ >>> print(replace_refs(json, merge_props=True))
85
+ {
86
+ "a": {"real": "b", "extra": "blah"},
87
+ "b": {"real": "b"}
88
+ }
89
+ >>> print(replace_refs(json))
90
+ {
91
+ "a": {"real": "b"},
92
+ "b": {"real": "b"}
93
+ }
94
+
95
+ This is against the JSON reference spec, but some other JSON reference libraries also
96
+ implement this behavior. It can be useful to e.g. extend common JSON schemas with extra
97
+ properties. This behavior should not be used if you want your JSON documents to be
98
+ usable with the widest possible array of tools.
99
+
43
100
A note on ``base_uri ``
44
101
--------------------
45
102
0 commit comments