microsoft / microsoft/typespec
Reusable prop declaration
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
# Property declaration proposal
## Problem
We have found in Azure that there is some common properties that are to be used in a pick and choose manner. For example I want to include a retryAfter header or a eTag.
The current approach is to create this model that is then spread
```tsp
model ETagHeader {
@header eTag: string;
}
```
Then to use it with spread.
```tsp
op test(...ETagHeader): void;
```
The problem with this approach is that you cannot customize that property. You cannot use it with versioning. This means as soon as you want to add a decorator, documentation or anything else you then have to redefine the property.
## Proposal
Introduce a new syntax to declare reusable properties. Using the keyword `prop`(or `property` both are reserved right now) and then the same syntax as a normal property.
```tsp
@header
prop eTag: string;
```
Those properties then could be used just like normal properties.
```tsp
model MyModel {
eTag,
}
```
or given a new name
```tsp
model MyModel {
myETag: eTag,
}
```
## Examples
```tsp
model MyModel {
/** With some docs */
eTag,
retryAfterX: retryAfter,
}
```
Contributor guide
Assessment
This issue has not been assessed yet.