Skip to content

Support fragment includes in $ref (e.g. file.json#/path/to/key) #223

@shuheng-liu

Description

@shuheng-liu

Background

#222 adds $ref support to JSON configs — a value of the form {"$ref": "path/to/other.json"} loads the entire referenced file. This is enough for the common case (factor a dataset_mixture into its own file).

Sometimes you want to reference only part of another file — e.g. pull a single named dataset entry out of a shared all_datasets.json rather than maintain one file per dataset. Standard JSON Pointer fragment syntax would express this as:

{
  "datasets": [
    {"$ref": "all_datasets.json#/droid_100"},
    {"$ref": "all_datasets.json#/aloha_cabinet"}
  ]
}

Proposed scope

  • Parse the fragment after # as a JSON Pointer (RFC 6901): /key1/key2/0/key3.
  • Resolve refs as today, then walk the pointer through the loaded structure.
  • Raise RefError with a helpful message if any pointer segment is missing.
  • Sibling-key deep-merge semantics carry over unchanged: if the resolved fragment is a JSON object, sibling keys merge in; otherwise sibling keys must be absent.
  • Cycle detection should account for (file_path, pointer) tuples, not just file paths, so two refs into different sub-keys of the same file aren't treated as a cycle but a self-referential pointer is.

Out of scope (separate follow-up)

Acceptance

  • New tests in tests/configs/test_refs.py covering: pointer to nested dict, pointer to list element, pointer to scalar, missing intermediate key, missing trailing key, sibling override on a fragment, fragment vs file cycle distinction.
  • Module docstring in src/opentau/configs/refs.py updated to describe the syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions