fix: avoid duplicate nullable type emission#1012
Open
z23cc wants to merge 1 commit into
Open
Conversation
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.
Summary
Fixes #1011.
This is a typify bug, not a progenitor bug. Progenitor converts OpenAPI
nullable: trueobject schemas into JSON Schematype: ["object", "null"], which typify already treats asOption<T>. The failure was in typify's registration/output flow for named schemas.Root cause
There are two related paths that could emit duplicate type definitions with the same Rust name:
For a required nullable definition with a metadata title, typify intended to name the inner type
<Name>Inner, but passed that asName::Suggested. The schema title then won and the inner type reused the outer name, producing a self-recursive newtype such as:A referenced definition can be preallocated with one
TypeIdwhile an earlier inline schema with the same title has already registered the same Rust type name under anotherTypeId. Emitting everyid_to_entryvalue then produced duplicate items.Reproducer
The regression test adds a small JSON Schema equivalent to the OpenAPI shape from the GitHub spec:
auto-mergehas titleAuto mergeand type["object", "null"]simple-userauthor_associationenum shares the title of a later referenced definitionThe test asserts that
AutoMergewrapsOption<AutoMergeInner>, does not wrapOption<AutoMerge>, and emitsAuthorAssociationonly once.Verification
cargo fmtRUSTC_WRAPPER= SCCACHE_DISABLE=1 cargo test -p typify-impl test_required_nullable_object_with_title_uses_distinct_inner_nameRUSTC_WRAPPER= SCCACHE_DISABLE=1 cargo test --workspaceRUSTC_WRAPPER= SCCACHE_DISABLE=1 cargo clippy --workspace[patch.crates-io]:cargo checkpassesbad_self_recursive = 0AutoMerge,AuthorAssociation,IssueField,IssueType,CodespaceMachine) each emit onceEOF 2>&1