-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to allow eager loading, or no proxies at all (1.0.0 beta) #43
Conversation
Add support to dereference without proxy objects. Add support to eagerly load all references.
I made a beta release on pypi. Feedback appriciated https://pypi.org/project/jsonref/1.0.0b3/ |
It was being shared from all places and adding confusion. jsonloader is now a plain function and easier to override.
New beta published. |
I kicked the tires on the new branch. |
Add new replace_refs kwargs to load utility functions
Thanks! And good catch. Added the new kwargs to those functions and pushed another beta. |
|
I'll give it another day or two for feedback before I cut the actual release. |
|
A couple things going on in this PR.
The main interface has been changed from
JsonRef.replace_refs
to a top level functionreplace_refs
. Just feels like it makes more sense, and I can't remember why it was a class method to start with. Also fixes (#22).JsonRef.replace_refs
is deprecated, but still works for now.jsonloader
has had the caching removed, and turned into a plain function rather than an instance of a special class. Caching of ref results is now handled directly byreplace_refs
. The previous caching behavior was a bit muddled, and this makes it easier for custom loaders to be implemented without worrying about caching. There is now no way to turn off caching (which was mostly the case previously as well, some of the caching was required for basic functionality.) If you want to pre-cache some URIs, it can be done by creating a custom loader function that loads from said cache.Due to multiple issues filed, three new options were added to
replace_refs
:lazy_load
option. When set to False, all references will be eagerly loaded. This can be useful because any errors will happen right on initial load, rather than when the reference is eventually accessed.proxies
option. When set to False, the resulting document won't haveJsonRef
objects in it at all, they will be replaced by the actual referred to data (Support $ref replacement without the proxies #9, Feature Request: when serializing, replace references with referents. #31). This can be nice when using with another library that doesn't work properly with the proxy objects, e.g. usingjson.dump
to output the document with the refs replaced (How to save to regular JSON without ref? #41). If used, this will of course mean you will be unable to output the document again with the refs intact.merge_props
argument. This was based on Preserve extra sibling attributes #35, and allows extra properties of json reference objects to be merged in to the document loaded by the reference. This is not part of the JSON reference spec, so is turned off by default.I'm hoping for some feedback on this PR, and testing by anyone using the repo. I might make a beta release on pypi for easier testing if needed. Open questions:
lazy_load
orproxies
be changed? My inclination would be to make the default still use proxies, but to eagerly load, so that all errors happen immediately.walk_refs
helper function, which is used internally to support these two new options this will recursively run a function on anyJsonRefs
in an object, (and optionally replace them with the result of the function.) Is this useful to make a public helper function, or is it not needed since the new options will use it directly?