Skip to content

Fix schema resolution when $id base URI differs from the loaded schema URI#1238

Merged
datho7561 merged 1 commit intoredhat-developer:mainfrom
shin19991207:fix-1236
Apr 23, 2026
Merged

Fix schema resolution when $id base URI differs from the loaded schema URI#1238
datho7561 merged 1 commit intoredhat-developer:mainfrom
shin19991207:fix-1236

Conversation

@shin19991207
Copy link
Copy Markdown
Member

What does this PR do?

The regression was introduced in #1186, where the added _preferLocalBaseForRemoteId sets a schema node’s baseUri to the local file path when a schema is loaded from a local file whose root $id ends 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 resourceIndexByUri stores 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 in resourceIndexByUri and 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 from
    This 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?

@shin19991207 shin19991207 requested a review from datho7561 as a code owner April 23, 2026 19:13
…a URI

Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and addresses the linked issue. Thanks, Morgan!

@datho7561 datho7561 merged commit cd3cba0 into redhat-developer:main Apr 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundled schema resolution fails for schemas with $id matching a file name

2 participants