Skip to content

[http-client-csharp] Preserve API versions on input models, enums, and properties #11799

Description

Background

TCGC exposes API-version availability at type and property granularity, but the C# emitter currently drops most of that metadata when converting TCGC SDK types into Microsoft.TypeSpec.Generator.Input types.

This blocks downstream C# generators from determining whether a model, enum, or property exists only in preview API versions or has also existed in a stable API version. Azure/azure-sdk-for-net#62567 needs this information to apply [Experimental] accurately in generated provisioning libraries.

Current behavior

With @azure-tools/typespec-client-generator-core 0.71.1, TCGC defines apiVersions: string[] on:

  • SdkClientType
  • SdkModelType
  • SdkEnumType
  • SdkModelPropertyTypeBase

The C# emitter currently preserves client.apiVersions in fromSdkClient, but does not preserve:

  • modelType.apiVersions in fromSdkModelType
  • sdkType.apiVersions in createEnumType
  • sdkProperty.apiVersions in fromSdkModelProperty

The corresponding C# input types also cannot currently retain this metadata:

  • InputClient has ApiVersions.
  • InputModelType does not have ApiVersions.
  • InputEnumType does not have ApiVersions.
  • InputModelProperty does not have ApiVersions.

As a result, a generated tspCodeModel.json retains client-level API versions but omits them from models, enums, and model properties.

Proposed change

Introduce API-version availability throughout the base C# generator input model:

  1. Add an ApiVersions property to InputModelType.
  2. Add an ApiVersions property to InputEnumType.
  3. Add an ApiVersions property to InputModelProperty.
  4. Update the TypeScript C# emitter converters to copy the corresponding TCGC apiVersions arrays.
  5. Update JSON deserialization, constructors, factories, mocks, and tests for the new members.

The values should preserve TCGC semantics and ordering rather than being recomputed by downstream generators.

Acceptance criteria

  • Model, enum, and model-property apiVersions from TCGC are present in the serialized C# code model.
  • Microsoft.TypeSpec.Generator.Input deserializes and exposes those values.
  • Existing client- and method-level API-version behavior remains unchanged.
  • Tests cover types and properties introduced in preview versions, types shared by preview and stable versions, and unversioned APIs.
  • Existing emitters and generators remain source-compatible where practical, using empty version lists for absent metadata.

Downstream scenario

Azure provisioning libraries need to mark a resource, model, enum, or property experimental only when it is available exclusively in preview API versions. If its API-version list contains at least one stable version, the API should not be marked experimental. Tracking issue: Azure/azure-sdk-for-net#62567.

Metadata

Metadata

Labels

emitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharpfeatureNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions