microsoft / microsoft/typespec
Allow visibility on union members
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
I have a scenario where I want to allow a more free-form input for usability reasons, but the service will normalize to a consistent form so API consumers don't need to handle all the weird cases. Visibility on union members would enable this nicely:
```
model Item {
tags: ItemLabel;
}
union ItemLabel {
// want to allow creating labels with just a string,
// but the service will normalize to the Label[]
@visibility("create", "update")
string[];
Label[];
}
model Label {
name: string;
color: string;
}
@post op create(item: Item): void;
@get op read(): Item;
```
This is a quite common pattern so I think this is fairly important.
Contributor guide
Assessment
This issue has not been assessed yet.