microsoft / microsoft/typespec
[python] Ser/deserialization for complex union cases have issues
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
transferred from https://github.com/Azure/autorest.python/issues/3006
This is derived from [discussion ](https://github.com/msyyc/typespec-e2e-demo/pull/2#discussion_r1889565930)e2e demo, the current ser/deserialization logic has issues to handle the complex union cases like below.
After confirmed with @msyyc we know that the current implementation would fail if our union contains more than one models. Or may also fail in other cases.
In this issue we may need to decide either to accept the current situation or re-design for un-supported cases.
```
@jsonSchema
model TodoFileBytesAttachment extends TodoAttachment {
kind: TodoAttachmentType.File;
/** The file contents */
file: bytes;
}
@jsonSchema
model TodoUrlAttachment extends TodoAttachment {
kind: TodoAttachmentType.Url;
/** A description of the URL */
description: string;
/** The url */
url: url;
}
@jsonSchema
model TodoAttachment {
/** discriminator kind */
kind: TodoAttachmentType;
}
@jsonSchema
union TodoAttachmentType {
string,
File: "file",
Url: "url",
}
```
Contributor guide
Assessment
This issue has not been assessed yet.