Skip to content

Support relative URI resolution in $dynamicRef #2928

Description

Problem

$dynamicRef values with relative URIs (e.g., ./external.yaml#node) are not resolved. FindDocumentByBaseUri compares the raw string against document base URIs, so a relative reference never matches an absolute document URI.

Example:

# Document A (baseUri: https://example.com/main.yaml)Tree:
properties:
next:
$dynamicRef: './external.yaml#node'# Document B (baseUri: https://example.com/external.yaml)ExternalNode:
$dynamicAnchor: nodetype: object

$dynamicRef: './external.yaml#node' should resolve to https://example.com/external.yaml (Document B), but FindDocumentByBaseUri('./external.yaml') cannot match https://example.com/external.yaml.

Proposed fix

Pass the host document's BaseUri to FindDocumentByBaseUri and resolve the relative reference via new Uri(baseUri, documentUri):

internalOpenApiDocument?FindDocumentByBaseUri(stringdocumentUri,Uri?baseUri){varresolved=baseUriis not null?newUri(baseUri,documentUri).ToString():documentUri;return_dynamicAnchorRegistryByDocument.Keys.Concat(_anchorRegistryByDocument.Keys).Distinct().FirstOrDefault(doc =>doc.BaseUri?.ToString().Equals(resolved,StringComparison.OrdinalIgnoreCase)==true);}

Scope

  • OpenApiWorkspace.FindDocumentByBaseUri — accept optional base URI parameter
  • OpenApiSchemaReference.Target — pass Reference.HostDocument.BaseUri
  • Tests — cross-document resolution with relative URIs

Related

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions