microsoft / microsoft/typespec

Incorrect serialization Code is Generated For Extensible Enums of Union Type

Open
#5,516 1 comment 0 reactions 0 assignees View on GitHub
emitter:client:csharp
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

When an union model property type is customized to an extensible enum of more than 1 type, ie `public readonly partial struct HyperparameterCycleCount : IEquatable, IEquatable` the underlying model is generating deserialization code that doesn't compile.

![Image](https://github.com/user-attachments/assets/046d25cf-6a13-4503-bc94-f3bc64d41870).

Similarly, the serialization code is generated incorrectly.

Sample spec: https://github.com/mikhail/openai-in-typespec/blob/c22818b1e6d61ffde44d19501e0ebacb13559eb9/.typespec/fine-tuning/custom.tsp#L5.
Sample generated code: https://github.com/mikhail/openai-in-typespec/blob/c22818b1e6d61ffde44d19501e0ebacb13559eb9/.dotnet/src/Generated/Models/HyperparameterOptions.Serialization.cs#L97

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.