Fix schema resolution when $id base URI differs from the loaded schema URI#1238
Merged
datho7561 merged 1 commit intoredhat-developer:mainfrom Apr 23, 2026
Merged
Conversation
…a URI Signed-off-by: Morgan Chang <shin19991207@gmail.com>
datho7561
approved these changes
Apr 23, 2026
Contributor
datho7561
left a comment
There was a problem hiding this comment.
Looks good and addresses the linked issue. Thanks, Morgan!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The regression was introduced in #1186, where the added
_preferLocalBaseForRemoteIdsets a schema node’s baseUri to the local file path when a schema is loaded from a local file whose root$idends with the same filename. In this case, the resolver effectively treated the local file URI as the base for resolving relative references.This behavior caused problems for embedded resource resolution. Because the resolver used the local file URI as the effective base, relative references could resolve against the wrong location. In particular, embedded resource references failed because
resourceIndexByUristores embedded resources under their original$id, not under a locally rewritten URI. As a result, internal references such as#/$defs/...could not find a corresponding item inresourceIndexByUriand thus could no longer be resolved correctly.The fix separates the schema’s logical resolution base from the source URI it was loaded from. This removes the behavior that preferred a same-named local file as the effective base for a remote
$id. Instead, the resolver now keeps these concerns distinct and only uses the source URI as a fallback when resolving external references to local sibling files. Now, we have:_baseUri: the logical resource URI derived from the schema’s$id_sourceUri: the URI of the file the schema was loaded fromThis separation ensures that logical resolution remains consistent with the schema’s
$id, while still allowing the source URI to be used for local file resolution.What issues does this PR fix or reference?
Fixes #1236
Is it tested? How?