[repo-assist] fix: prevent duplicate ProvidedTypeDefinition for named component aliases - #478
Merged
sergey-tihon merged 6 commits intoJul 29, 2026
Conversation
…ases (#477) When a named component schema is a single-ref oneOf/anyOf/allOf wrapper that resolves to another named object component, registerInNsAndInDef was calling ns.RegisterType for a ProvidedTypeDefinition that was already registered under a different component path. This caused GetProvidedTypes() to return the same PTD twice, resulting in 'duplicate entry in type index table' during assembly emit. Fix: before calling ns.RegisterType, check whether the ProvidedTypeDefinition is already present in pathToType.Values (meaning it was registered for another path). If so, skip the namespace registration — the pathToType cache entry for the alias path is still added, so lookups continue to resolve correctly. Adds 4 regression tests covering oneOf/allOf/anyOf named alias cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jul 28, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a type-provider assembly emission failure (FS3033) caused by named OpenAPI component aliases (oneOf/anyOf/allOf with a single $ref) registering the same ProvidedTypeDefinition more than once. It does so by separating “cache component path → resolved type” from “register newly created provided types in the generated namespace”, and adds regressions to ensure only one referenced type is emitted.
Changes:
- Split component-path caching (
pathToType) from namespace registration so aliases only cache their resolved type instead of registering it again. - Ensure top-level named enums are still registered at their creation site (now that the prior unconditional registration was removed).
- Strengthen unit tests to assert exactly one referenced type is produced, and add a provider-level regression covering named object alias emission.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/SwaggerProvider.DesignTime/DefinitionCompiler.fs |
Separates path caching from namespace registration; caches alias paths without double-registering provided types; registers enums at creation. |
tests/SwaggerProvider.Tests/Schema.V3SchemaCompilationTests.fs |
Tightens single-ref composite-schema tests to assert exactly one referenced type is emitted. |
tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj |
Adds the new provider-level regression test file to the project. |
tests/SwaggerProvider.ProviderTests/Swagger.NamedObjectAliases.Tests.fs |
Provider regression verifying the aliased response resolves to the referenced object type (and indirectly that assembly emission succeeds). |
tests/SwaggerProvider.ProviderTests/Schemas/v3/named-object-alias-oneof.json |
Minimal OpenAPI v3 schema reproducing the named oneOf alias scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sergey-tihon
deleted the
repo-assist/fix-issue-477-named-alias-duplicate-type-2903dafaff948372
branch
July 29, 2026 18:47
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 #477: named OpenAPI components that are single-reference
oneOf/anyOf/allOfaliases no longer register the referencedProvidedTypeDefinitiontwice and fail assembly emission withFS3033.This branch now includes and consolidates #479.
Fix
ProvidedTypeDefinitioninstances only where they are createdpathToType.ValuesThis preserves alias
$refresolution while ensuring each generated type is emitted only once.Tests
allOf,oneOf, andanyOfunit tests to require exactly one referenced typeValidation
./build.sh -t CheckFormat./build.sh -t Build— succeeded with warnings only./build.sh -t RunTestsFixes #477
Supersedes #479