feat: add deduplicateRefsIgnoringKeys option to structural hash - #682
Open
klear-jason wants to merge 6 commits into
Open
feat: add deduplicateRefsIgnoringKeys option to structural hash#682klear-jason wants to merge 6 commits into
klear-jason wants to merge 6 commits into
Conversation
- Add structural hash-based deduplication for schemas with same title - Track emitted type names in generator to prevent duplicate declarations - Schemas with identical title and structure now reuse same type definition - Different structures with same title get unique numbered names (e.g. Option, Option1) - Add comprehensive test coverage for duplicate sub-schema scenarios
Add four test fixtures covering: - NAMED_ENUM dedup with matching title - NAMED_ENUM dedup without title (property name match) - UNNAMED_ENUM dedup with matching title - Mixed scenario (identical + non-identical enums)
Previously the dedup cache in standaloneName() only activated when
schema.title was present. Without a title, identical enum schemas on
same-named properties bypassed the cache and received fresh names
(Status, Status1, Status2...) instead of deduplicating.
Remove the if (schema.title) guard so the cache runs whenever name
is available. Change cache key from ${schema.title}::${hash} to
${name}::${hash} to cover all named schemas.
…attern declareEnums() used object-identity dedup (Set<AST>). Two distinct AST objects with the same standaloneName both emitted declarations, producing duplicates in the output. Add emittedNames: Set<string> parameter (default new Set<string>()) and check ast.standaloneName before emitting, matching the existing pattern in declareNamedInterfaces() and declareNamedTypes(). Pass emittedNames through all 5 recursive call sites (ARRAY, UNION, INTERSECTION, TUPLE, INTERFACE). Each declare function retains its own independent set.
New snapshots for four duplicate-enum fixtures, each showing a single declaration instead of duplicates. Existing real-world snapshots (FHIR, Azure, schemaStore, arrayAdditionalItems) are reduced where previously-duplicate enum and interface declarations are now correctly deduplicated. All 169 tests pass.
Adds a new deduplicateRefsIgnoringKeys option (default []) that excludes specified schema keys from the structural hash used to deduplicate $ref types. The canonical use case: when the same $ref appears on multiple properties with different description values, deduplicateRefsIgnoringKeys: ['description'] causes those properties to share a single type declaration instead of generating suffixed duplicates (MoneySchema, MoneySchema1…). Descriptions are preserved as JSDoc on the property rather than forking a new type. Builds on the structural hash deduplication introduced in this branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new
deduplicateRefsIgnoringKeysoption (default[]) that excludes specified schema keys from the structural hash used to deduplicate $ref types.The canonical use case: when the same $ref appears on multiple properties with different
descriptionvalues,deduplicateRefsIgnoringKeys: ['description']causes those properties to share a single type declaration instead of generating suffixed duplicates (MoneySchema, MoneySchema1…). Descriptions are preserved as JSDoc on the property rather than forking a new type.