Skip to content

[repo-assist] fix: prevent duplicate ProvidedTypeDefinition for named component aliases - #478

Merged
sergey-tihon merged 6 commits into
masterfrom
repo-assist/fix-issue-477-named-alias-duplicate-type-2903dafaff948372
Jul 29, 2026
Merged

[repo-assist] fix: prevent duplicate ProvidedTypeDefinition for named component aliases#478
sergey-tihon merged 6 commits into
masterfrom
repo-assist/fix-issue-477-named-alias-duplicate-type-2903dafaff948372

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #477: named OpenAPI components that are single-reference oneOf/anyOf/allOf aliases no longer register the referenced ProvidedTypeDefinition twice and fail assembly emission with FS3033.

This branch now includes and consolidates #479.

Fix

This preserves alias $ref resolution while ensuring each generated type is emitted only once.

Tests

  • strengthened the existing allOf, oneOf, and anyOf unit tests to require exactly one referenced type
  • retained one focused provider-level regression that exercises real type-provider assembly emission and verifies the alias response resolves to the referenced object type
  • removed duplicate schemas and broader alias-graph tests that were not needed for issue Named object component aliases emit duplicate provided type #477

Validation

  • ./build.sh -t CheckFormat
  • ./build.sh -t Build — succeeded with warnings only
  • ./build.sh -t RunTests
    • unit tests: 548 total, 0 errors, 0 failed, 1 skipped
    • provider tests: 128 total, 0 errors, 0 failed

Fixes #477
Supersedes #479

…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>
@sergey-tihon
sergey-tihon marked this pull request as ready for review July 29, 2026 17:24
Copilot AI review requested due to automatic review settings July 29, 2026 17:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
sergey-tihon merged commit 5397c97 into master Jul 29, 2026
10 checks passed
@sergey-tihon
sergey-tihon deleted the repo-assist/fix-issue-477-named-alias-duplicate-type-2903dafaff948372 branch July 29, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Named object component aliases emit duplicate provided type

3 participants