microsoft / microsoft/typespec
[Feature request] [protobuf] nested definitions
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Clear and concise description of the problem
There's no support for nested definitions. Nested could be enums or other messages.
```
message FeaturedElement {
enum FeatureElementType {
FEATURED_ELEMENT_TYPE_UNSPECIFIED = 0;
FEATURED_ELEMENT_TYPE_PRODUCT = 1;
FEATURED_ELEMENT_TYPE_ITEM = 2;
}
string id = 1;
int32 position =2;
FeatureElementType element_type = 3;
}
```
I'm not sure if nesting models should be supported by all emitters, if so then it can be done by a decorator, like this:
```
model FeaturedElement {
@field(1)
id: string;
@field(2)
position: int32;
@field(3)
element_type: FeatureElementType;
}
@parent(FeaturedElement)
enum FeatureElementType {
FEATURED_ELEMENT_TYPE_UNSPECIFIED: 0,
FEATURED_ELEMENT_TYPE_PRODUCT: 1,
FEATURED_ELEMENT_TYPE_ITEM: 2,
}
```
Nesting is used quite widely in our codebase and it could be a blocker for us in typespec adoption.
I can try to implement it if someone can give me a clue where to begin 😄
### Checklist
- [X] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [docs](https://typespec.io/docs/).
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Contributor guide
Assessment
This issue has not been assessed yet.