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:
- Add an
ApiVersions property to InputModelType.
- Add an
ApiVersions property to InputEnumType.
- Add an
ApiVersions property to InputModelProperty.
- Update the TypeScript C# emitter converters to copy the corresponding TCGC
apiVersions arrays.
- 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.
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.Inputtypes.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-core0.71.1, TCGC definesapiVersions: string[]on:SdkClientTypeSdkModelTypeSdkEnumTypeSdkModelPropertyTypeBaseThe C# emitter currently preserves
client.apiVersionsinfromSdkClient, but does not preserve:modelType.apiVersionsinfromSdkModelTypesdkType.apiVersionsincreateEnumTypesdkProperty.apiVersionsinfromSdkModelPropertyThe corresponding C# input types also cannot currently retain this metadata:
InputClienthasApiVersions.InputModelTypedoes not haveApiVersions.InputEnumTypedoes not haveApiVersions.InputModelPropertydoes not haveApiVersions.As a result, a generated
tspCodeModel.jsonretains 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:
ApiVersionsproperty toInputModelType.ApiVersionsproperty toInputEnumType.ApiVersionsproperty toInputModelProperty.apiVersionsarrays.The values should preserve TCGC semantics and ordering rather than being recomputed by downstream generators.
Acceptance criteria
apiVersionsfrom TCGC are present in the serialized C# code model.Microsoft.TypeSpec.Generator.Inputdeserializes and exposes those values.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.