Skip to content

[http-client-csharp] Remove internal models referenced only by BinaryData union metadata #11845

Description

@live1206

Description

The C# generator represents TypeSpec unions as BinaryData while retaining the original union item types as metadata on CSharpType. The provider reference map currently treats that metadata as a reachability edge even when a variant is explicitly internal.

As a result, an internal model whose only inbound reference is an erased BinaryData union item is still emitted, even though no generated CLR signature or implementation code uses the model. Public XML documentation may also mention that inaccessible model.

The current behavior is covered by ProviderReferenceMapAnalyzerTests.BinaryDataUnionPropertyDoesNotPublicizeInternalUnionMembers, introduced in #11288 during the provider-reference-map migration. The test ensures that the variant is not promoted to public, but also requires ShouldWriteProvider to return true. Investigation did not find a concrete runtime or product requirement for retaining the model; the assertion appears to preserve migration behavior.

This was discussed in #11839 while fixing loss of union metadata during back-compat type replacement. Metadata preservation and the policy for interpreting that metadata should remain separate concerns.

Desired behavior

  • An explicitly internal variant referenced only through erased BinaryData union metadata should not be considered reachable and should not be emitted.
  • An internal variant with a genuine implementation dependency—such as generated serialization code, custom code, a discriminator relationship, or another concrete generated reference—should remain internal and be emitted.
  • Existing API-contract/baseline retention should continue to apply independently.
  • Public union variants and their public-surface reachability should remain unaffected.
  • Public XML documentation should not reference internal or removed union variants.

Test coverage

Replace or split BinaryDataUnionPropertyDoesNotPublicizeInternalUnionMembers so coverage independently verifies:

  1. An internal variant referenced only by BinaryData union metadata is not written.
  2. An internal variant with a real implementation reference remains internal and is written.
  3. Public XML documentation excludes internal or removed union variants.

Context

- by copilot

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions