Skip to content

feat: support external $dynamicRef resolution #3902

@aqeelat

Description

@aqeelat

Summary

$dynamicRef values that point to external files (e.g., $dynamicRef: 'other.json#node') currently fall back to unknown in generated TypeScript output.

Why

The bundler (@hey-api/json-schema-ref-parser) only resolves $ref URIs — it fetches external files and inlines them into the bundled spec. $dynamicRef is invisible to the bundler, so external files are never fetched and the anchor is never available for dynamic scope resolution.

What's needed

  1. @hey-api/json-schema-ref-parser: Add isExternalDynamic$Ref() check in the crawl phase (resolve-external.ts), mirroring the existing isExternal$Ref() path. Fetch external files referenced by $dynamicRef, parse them, and add them to the $refs cache. The $dynamicRef string itself should be preserved (not rewritten to $ref) so the parser's dynamic scope resolution continues to work.

  2. @hey-api/shared (parser): After bundling brings the external schemas inline, resolveDynamicRef() may need to handle cases where the $dynamicRef URI now points to a bundled-in anchor rather than an external one.

Current behavior

# spec.yaml
components:
  schemas:
    Container:
      type: object
      properties:
        item:
          $dynamicRef: 'other.json#node'
// Generated output
export type Container = { item: unknown };

Expected behavior

// After fix
export type Container = { item: Node };

Workaround

Move the referenced schemas into the main spec file under components.schemas and use internal $dynamicRef + $dynamicAnchor instead of external references.


If you need this feature, please upvote this issue with a 👍 reaction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions