I'm working on fixing python-jsonschema/check-jsonschema#640 , which is a bit of weirdness to do with local schemas and multiple relative $ref values.
Right now, check-jsonschema is doing some path joining logic to combine the file URI for the input schema with the $ref paths it sees, and it ends up playing out incorrectly when combined with referencing's inner resolver object. Second order ref retrieval does some path joining, which then joins improperly with the explicit base URI.
I found that the issue can be resolved by replacing the Validator._resolver with one that has a non-"" base URL:
if validator._resolver._base_uri == "" and retrieval_uri is not None:
validator._resolver = reference_registry.resolver(base_uri=retrieval_uri)
(where retrieval_uri is, in this case, the local file URI)
I don't see an obvious public-API way of doing this. The above is a workaround, and I'll probably do a version of it with some safeguard around potential jsonschema and referencing changes. I rejected my other options as being worse workarounds:
- modifying the input schema to set
"$id" -- although this has the right effect, it strikes me as incorrect (I'm not able to substantiate that with some case in which there's a bad outcome, but it's silently tweaking the user's data to make things work; feels weird IMO)
- subclassing
Resource from referencing to override id() ... based on jsonschema's interfaces, I strongly suspect that this is not intended usage
What would work best is to have some public API way of explicitly setting the base URI for resolution. It probably needs support in referencing, but it also potentially needs to be exposed in jsonschema.
I'm working on fixing python-jsonschema/check-jsonschema#640 , which is a bit of weirdness to do with local schemas and multiple relative
$refvalues.Right now,
check-jsonschemais doing some path joining logic to combine the file URI for the input schema with the$refpaths it sees, and it ends up playing out incorrectly when combined withreferencing's inner resolver object. Second order ref retrieval does some path joining, which then joins improperly with the explicit base URI.I found that the issue can be resolved by replacing the
Validator._resolverwith one that has a non-""base URL:(where
retrieval_uriis, in this case, the local file URI)I don't see an obvious public-API way of doing this. The above is a workaround, and I'll probably do a version of it with some safeguard around potential
jsonschemaandreferencingchanges. I rejected my other options as being worse workarounds:"$id"-- although this has the right effect, it strikes me as incorrect (I'm not able to substantiate that with some case in which there's a bad outcome, but it's silently tweaking the user's data to make things work; feels weird IMO)Resourcefromreferencingto overrideid()... based onjsonschema's interfaces, I strongly suspect that this is not intended usageWhat would work best is to have some public API way of explicitly setting the base URI for resolution. It probably needs support in
referencing, but it also potentially needs to be exposed injsonschema.