Skip to content

fix(library): avoid false circular refs for external schema re-exports#2873

Open
baywet wants to merge 1 commit into
mainfrom
fix/invalid-circular-ref
Open

fix(library): avoid false circular refs for external schema re-exports#2873
baywet wants to merge 1 commit into
mainfrom
fix/invalid-circular-ref

Conversation

@baywet

@baywet baywet commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

  • stop OpenApiWorkspace.RegisterComponents from dereferencing schema refs while registering component aliases
  • keep $id-based registration for concrete schemas so canonical identifier lookups still work
  • add a regression test for the split-file OpenAPI 3.1 re-export scenario from LoadExternalRefs: false-positive "Circular reference detected" #2872

Why

Fixes #2872.

The faulty behavior was introduced by #1826, which added the item.Value.Id ?? ... fallback in schema registration to support identifier-based resolution. That was correct for concrete schemas, but it is unsafe for OpenApiSchemaReference because accessing Id resolves the external target eagerly during workspace registration.

JSON Schema reference-resolution implications

Under JSON Schema 2020-12, a JSON Pointer can still address a lexical location within the containing document, but $id defines the canonical URI of a schema resource. For this code path, component registration should therefore:

  • always register the component-key alias for schema references
  • only register $id aliases for concrete schemas that already own that canonical identifier
  • avoid dereferencing references during registration, because registration is establishing lookup keys, not traversing schema resources

@baywet baywet requested a review from a team as a code owner June 9, 2026 11:28
@github-code-quality

github-code-quality Bot commented Jun 9, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage remains at 88%, unchanged from the branch.


Updated June 09, 2026 12:05 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

Fixes #2872.

The false positive came from workspace schema registration preferring
item.Value.Id for component aliases. For OpenApiSchemaReference values,
reading Id eagerly dereferenced the external target during registration,
which triggered "Circular reference detected while resolving schema"
for a root schema re-export plus a direct external reference.

This faulty behavior traces back to PR #1826, which introduced the
item.Value.Id ?? fallback to support JSON Schema identifier-based
resolution. Under JSON Schema 2020-12, JSON Pointer still identifies a
lexical location in the containing document, but $id establishes the
canonical schema resource URI. This change preserves explicit $id alias
registration for concrete schemas while always registering component keys
for schema references so workspace registration does not resolve refs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

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.

LoadExternalRefs: false-positive "Circular reference detected"

1 participant