fix(openapi3): Fix duplicate type name error for unreachable derived models with visibility properties - #11427
Merged
Merged
Conversation
|
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. |
4 tasks
…with visibility properties When a model with @visibility(Lifecycle.Create, Lifecycle.Update) properties extends another model and both are unreachable from HTTP operations, processUnreferencedSchemas would emit the derived model with Visibility.All context, while modelDeclaration would also emit it by inheriting the parent's reduced Read context. These two different contexts resulted in two schema declarations with the same name, causing a 'Duplicate type name' error. Fix: Emit unreachable derived models with explicit Visibility.All context in modelDeclaration to match the context used by processUnreferencedSchemas, ensuring the TypeEmitter cache deduplication works correctly. Fixes #9727 Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix duplicate type name issue in model definitions
fix(openapi3): Fix duplicate type name error for unreachable derived models with visibility properties
Jul 28, 2026
commit: |
timotheeguerin
marked this pull request as ready for review
July 29, 2026 15:39
timotheeguerin
requested review from
catalinaperalta,
iscai-msft,
markcowl and
xirzec
as code owners
July 29, 2026 15:39
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
iscai-msft
approved these changes
Jul 30, 2026
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.
When a model with
@visibility(Lifecycle.Create, Lifecycle.Update)properties extends another model, and both are unreachable from HTTP operations, the OpenAPI3 emitter throwsDuplicate type name: 'Account'.Root Cause
Two code paths independently emit the derived model with different visibility contexts, bypassing the TypeEmitter deduplication cache:
processUnreferencedSchemasemitsAccountwithVisibility.Allcontext (correct for unreachable types).modelDeclarationemitsAccountas a derived model inheriting the parent's reduced context (Visibility.Read— becauseObjecthas no transformed properties, soreduceContextdowngrades it).isTransformed(Account, All) = true(sinceitem_idis present inAllbut absent inRead), so path 1 keepsAllwhile path 2 producesRead. Two distinct cache keys → two#createDeclarationcalls → same name → error.Fix
In
modelDeclaration, emit unreachable derived models with an explicit{ visibility: Visibility.All }referenceContext, matching whatprocessUnreferencedSchemasuses. This makes both paths produce the same context key — the TypeEmitter cache deduplicates on the second call.Files changed:
packages/openapi3/src/schema-emitter.ts— checkisUnreachableper derived model inmodelDeclarationloop; if unreachable, forceVisibility.AllreferenceContextpackages/openapi3/test/metadata.test.ts— add regression test for this case