Add some way of resolving out-of-schema references
I really don't like references to other schemas, because they make the meaning temporally variable and unreliable - the referenced schema can change or become inaccessible. Dealing with them also adds IO, which makes everything harder.
Nonetheless, they are useful and in practice widely used, so we can't ignore them forever. I would therefore like to add a function which fetches external schemas, adds them to a definitions section, and rewrites the $ref keys to point to the new in-schema copies.
The actual from_schema() implementation can then continue to ignore IO, and any problems will at least be isolated in their own function!
@Zac-HD where would such a function be placed in the codebase, if we are only to rewrite refs and just add external dependencies as such this could be fairly straightforward to implement...
More desirably, we could have a user-defined Resolver for external references which would point (and load) the schemas and within the library, we'd perform only the write whenever a ref tag that refers to a resolved external schema is encountered.
This would be a new top-level function, hypothesis_jsonschema.load_external_refs(schema: Schema) -> Schema.
I'd define it in a new _external_refs.py file, since nothing else should depend on this, and then import whatever machinery is useful from _canonicalise.py. I don't (yet) have any opinion on how it should work, since this is mostly to support workflows that I don't have any real experience with - your proposal sounds good though.
This extremely useful for our use case so I'd be keen to make this happen, just wanted a bit of lee-way on where to start. I think I'll take a jab at this and get back to you if I make any meaningful progress :)
Awesome, thanks! Please open a PR once you have something - early feedback is the best kind and I'm always happy to review unfinished contributions.