fix(schema): resolve representation identifiers by AST identity - #6782
Conversation
🦋 Changeset detectedLatest commit: 56e8121 The changes in this PR will be included in the next version bump. This PR includes changesets to release 29 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- AST identity-based reference deduplication —
getIdentityKey/getCanonicalASTreplace structuralhasSameReferenceOwnerchecks, so structurally identical encoded ASTs share references even across distinct schema instances. - Duplicate identifiers suffix instead of throwing — referentially distinct schemas with the same
identifieror~identifiernow get numeric suffixes (Value,Value_1,Value_2) rather than a hard error. - Fallback naming:
JsonEncoding→Encoded— more general and clearer. Propagated through all test expectations and the OpenAPI/HttpApi snapshot. toCodecJsonASTsimplified — ~55 lines of identifier-propagation logic removed; that responsibility now lives intoRepresentation'sresolveReferenceIdentifier.- 6 old tests removed, 4 new tests added — old
toCodecJsonASTidentifier-propagation tests replaced by equivalent (and more thorough)toRepresentation-level tests for fallback resolution and encoded/type-side annotation precedence.
The algorithmic change is sound: getIdentityKey builds a stable key from _tag + getValueId of all non-context properties, getCanonicalAST maps structural duplicates to the first-seen canonical, and the visiting/visited/shared tracking operates on that canonical to correctly handle recursive and shared structures. All affected tests pass.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Simplified
getCanonicalAST— thecontext ===guard was removed. When two ASTs are structurally identical (same identity key), the first-seen canonical always wins. This fixes a bug wherereplaceContext-created ASTs with identical contexts were not recognized as equivalent and failed to share references. - Added
replaceContextsharing test —toRepresentations.test.tsnow directly tests that twoSchemaAST.replaceContext(ast, context)calls with the same context produce shared references, validating the canonicalization fix. - Reorganized tests —
toRepresentation.test.tsandtoRepresentations.test.tsrestructured into logicaldescribeblocks ("node conversion","root identity and sharing","identifier collisions"). Identifier collision tests now assert suffix-based output instead ofassert.throws. - Updated docs —
SCHEMA.mdnow mentions that context-equivalent AST copies are canonicalized and share references.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

No description provided.