You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The C# generator produces double instead of float when a multipart model property declared as HttpPart<numeric> is decorated with a property-level @alternateType(float32, "csharp"). The same problem occurs with @alternateType(HttpPart<float32>, "csharp").
The C# conversion layer and .NET generator appear to map the received SDK types correctly (Float32 to float and Numeric to double). The issue is that the property-level alternate type is lost during TCGC multipart model construction.
In the upstream addMultipartPropertiesToModelType path, the property is initially created through getSdkModelPropertyType(part.property), which honors the alternate type. The implementation then obtains the unwrapped payload via getHttpBodyType(part.body) and replaces clientProperty.type with getClientTypeWithDiagnostics(bodyType), discarding the type selected from the decorated property.
The likely fix is in the TCGC multipart-model construction path, specifically addMultipartPropertiesToModelType in packages/typespec-client-generator-core/src/types.ts: preserve a regular alternate type attached to part.property when replacing the synthetic HttpPart wrapper with its payload type, while retaining existing diagnostics for unsupported external-property alternates.
Suggested regression coverage:
HttpPart<numeric> with @alternateType(float32, "csharp") produces SDK type float32.
The C# emitter model conversion yields a Float32 input primitive.
Describe the bug
The C# generator produces
doubleinstead offloatwhen a multipart model property declared asHttpPart<numeric>is decorated with a property-level@alternateType(float32, "csharp"). The same problem occurs with@alternateType(HttpPart<float32>, "csharp").The C# conversion layer and .NET generator appear to map the received SDK types correctly (
Float32tofloatandNumerictodouble). The issue is that the property-level alternate type is lost during TCGC multipart model construction.In the upstream
addMultipartPropertiesToModelTypepath, the property is initially created throughgetSdkModelPropertyType(part.property), which honors the alternate type. The implementation then obtains the unwrapped payload viagetHttpBodyType(part.body)and replacesclientProperty.typewithgetClientTypeWithDiagnostics(bodyType), discarding the type selected from the decorated property.Reproduction
Expected generated C# property type:
float.Actual generated C# property type:
double.Also reproduces with:
Relevant investigation:
createSdkContext; the C# conversion layer consumes the already-overwritten SDK property type.Float32tofloatandNumerictodouble, indicating that the incorrect type reaches the generator before C# mapping.HttpPart<File>andHttpPart<bytes>, but do not cover property-level alternates.HttpPartproperties.HttpPartproperty. microsoft/typespec#8820The likely fix is in the TCGC multipart-model construction path, specifically
addMultipartPropertiesToModelTypeinpackages/typespec-client-generator-core/src/types.ts: preserve a regular alternate type attached topart.propertywhen replacing the syntheticHttpPartwrapper with its payload type, while retaining existing diagnostics for unsupported external-property alternates.Suggested regression coverage:
HttpPart<numeric>with@alternateType(float32, "csharp")produces SDK typefloat32.Float32input primitive.floatproperty.numeric/double.Checklist