Closed msyyc closed 10 months ago
I think union is convenient for typespec definition but not good feature for SDK users. Reason: (1) It is very hard to deserialization when runtime for SDK. (2) Even if SDK can deserialize for Union type, SDK users still need to check whether specific property exists so that they can confirm the property type of returned model
Here is the real case that is used by OpenAI: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/OpenAI.Inference/models/images.tsp#L85
closing because this will be solved during tcgc adoption #2266
using TypeSpec.Http;
@doc("Illustrates inheritance and polymorphic model.") @scenarioService("/type/model/inheritance") namespace Test.Union;
@doc("Cat") model Cat { eatFish: boolean; }
@doc("Dog") model Dog { eatBone: boolean; }
@doc("Animal") model Animals { content: Cat[] | Dog[]; }
@route("/test/union") interface Discriminated { @scenario @scenarioDoc("test") @get getAnimal(): Animals; }