microsoft / microsoft/typespec
key decorator behavior in inheritance structures
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
My background: I'm currently writing a PostgreSQL emitter for TypeSpec.
As far as I understand the docs the "key"-decorator should "Mark a model property as the key to identify instances of that type"
Now in an inheritance structure it is allowed that every model has one key, leaving child-models with more than one key-property.
```
model Child extends Parent {
@key id: numeric;
}
model Parent {
@key parentKey: string;
}
```
[Playground Link](https://cadlplayground.z22.web.core.windows.net/?c=bW9kZWwgQ2hpbGQgZXh0ZW5kcyBQYXJlbnQgewogIEBrZXkgaWQ6IG51bWVyaWM7Cn0KCsY00CZwxRBLZXk6IHN0cmluZzsKfQ%3D%3D)
At least in my case this should throw an error and I can't think of any circumstance where the "key"-decorator should be allowed multiple times in an inheritance structure.
If there are cases, where this should be allowed this is just an issue to update the docs about it, as I will write my own error-handling for this for now.
As the key decorator is not emitted to openAPI this doesn't cause any issues in it.
Contributor guide
Assessment
This issue has not been assessed yet.