microsoft / microsoft/typespec

Allow visibility on union members

Open
#2,926 5 comments 0 reactions 0 assignees View on GitHub
triaged:core
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

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.