Skip to content

Keep references intact when canonicalizing Draft 3 schemas - #1091

Open
Vansh-kap-98 wants to merge 1 commit into
sourcemeta:mainfrom
Vansh-kap-98:draft3-preserve-refs
Open

Vansh-kap-98 wants to merge 1 commit into
sourcemeta:mainfrom
Vansh-kap-98:draft3-preserve-refs

Conversation

@Vansh-kap-98

@Vansh-kap-98 Vansh-kap-98 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Two rules dropped a $ref while rewriting a schema, changing what it accepts. Neither needs an id.

type_union_distribute_keywords copies a keyword into every type union branch it applies to. When the value holds a reference, or a reference points into it, the copy duplicates it. The canonicaliser repairs references after a transform, but only the origin it recorded beforehand, so the second copy is left pointing at a path that no longer exists and ends up as {}:

{
  "$schema": "http://json-schema.org/draft-03/schema#",
  "type": [
    { "type": "object", "patternProperties": { "^a": {} } },
    { "type": "object", "patternProperties": { "^b": {} } }
  ],
  "properties": {
    "foo": { "type": "integer" },
    "bar": { "$ref": "#/properties/foo" }
  }
}

<!-- This is an auto-generated description by cubic. -->
<a href="https://cubic.dev/pr/sourcemeta/blaze/pull/1091?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

type_union_distribute_keywords copied a keyword into several type union branches, duplicating any reference the value held or pointed into, and only one copy was ever repaired. It now wraps in those cases, as it already does for identifiers.

dependencies_to_extends_disallow moved each dependency schema into an implication wrapper without rewriting references, so a pointer into dependencies was lost outright. It now reports where each schema landed.

Signed-off-by: Vansh <officialbusiness9818@gmail.com>
@Vansh-kap-98
Vansh-kap-98 marked this pull request as ready for review September 26, 2026 03:52

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

@augmentcode

augmentcode Bot commented Sep 26, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR preserves local references while canonicalizing Draft 3 schemas.

Changes:

  • Tracks schema-valued dependencies as they move into Draft 3 implication wrappers.
  • Accounts for pre-existing extends branches when recording each new destination.
  • Rewrites references targeting a moved dependency to its new wrapper location.
  • Detects type-union keywords whose values contain references or are reference targets.
  • Wraps such unions in extends rather than duplicating those keyword values.
  • Adds a frame-based helper that identifies affected top-level keywords.
  • Retains the existing identifier/anchor duplication safeguard.
  • Adds a regression test for a reference inside distributed properties.
  • Adds a regression test for a reference into a dependency schema.
  • Asserts the resulting reference paths in canonical Draft 3 output.
  • Continues validating the expected output against the canonical Draft 3 metaschema.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

This branch has not been deployed

No deployments
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.

1 participant