Skip to content

json-schema: key bundled $defs entries by explicit @id to prevent silent overwrite - #11505

Open
timotheeguerin with Copilot wants to merge 5 commits into
mainfrom
copilot/bug-fix-duplicate-id-resolution
Open

json-schema: key bundled $defs entries by explicit @id to prevent silent overwrite#11505
timotheeguerin with Copilot wants to merge 5 commits into
mainfrom
copilot/bug-fix-duplicate-id-resolution

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

In bundleId mode, schemas with the same declaration name could still collide in $defs even after @@id assigned distinct identities. This suppressed duplicate-id diagnostics while still dropping one type due to name-based $defs keying.

  • Root cause

    • Bundled $defs keys were derived from declaration names (decl.name), not explicit @id values.
    • With duplicate names across namespaces, one entry overwrote the other in the bundle.
  • Emitter behavior change

    • Track explicit @id per emitted declaration.
    • Use explicit @id as the $defs key when present.
    • Preserve existing fallback behavior (decl.name) for declarations without explicit @id.
  • Regression coverage

    • Added a focused test for two @jsonSchema namespaces each declaring Equals, then assigning:
      • @@id(StringExpressions.Equals, "StringEquals")
      • @@id(IntegerExpressions.Equals, "IntegerEquals")
    • Assert both schemas are present in $defs under distinct keys.
    • Updated existing bundle+baseUri explicit-id assertion to validate the new keying behavior.
@jsonSchema
namespace StringExpressions { model Equals { equals: string; } }

@jsonSchema
namespace IntegerExpressions { model Equals { equals: integer; } }

@@id(StringExpressions.Equals, "StringEquals");
@@id(IntegerExpressions.Equals, "IntegerEquals");

// bundleId output now contains:
// $defs.StringEquals and $defs.IntegerEquals

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate-id error resolution in bundleId mode json-schema: key bundled $defs entries by explicit @id to prevent silent overwrite Jul 31, 2026
Copilot AI requested a review from timotheeguerin July 31, 2026 12:33

@timotheeguerin timotheeguerin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot fix comments

Comment thread .chronus/changes/copilot-bug-fix-duplicate-id-resolution-2026-6-31-12-29-40.md Outdated
Comment thread packages/json-schema/test/ids.test.ts Outdated
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix comments

Addressed in c376066.

  • Updated the changelog sentence formatting.
  • Simplified the regression test to use direct @id(...) decorators (no augment decorators), while keeping the same $defs-key behavior assertions.

@pkg-pr-new

pkg-pr-new Bot commented Jul 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/json-schema@11505

commit: 5f8c944

Comment thread packages/json-schema/test/ids.test.ts Outdated
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI requested a review from timotheeguerin July 31, 2026 13:56
@timotheeguerin
timotheeguerin marked this pull request as ready for review July 31, 2026 15:47
@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Title: @@id augment in bundleId mode silently resolves duplicate-id error but still drops types — $defs key should use @id value

2 participants