Key name collisions are detected when a singleton resource is parented to another singleton resource.
- Dominant language
- TypeScript
- Stars
- 27
- Forks
- 90
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 156
Description
In ScVmm, there is a singleton that is parented to another singleton, like this:
```tsp
@singleton
model VirtualMachineInstance
is ExtensionResource {
/** Name of the virtual machine instance. */
@key
@segment("virtualMachineInstances")
@visibility("read")
@path
name: string;
}
@parentResource(VirtualMachineInstance)
@singleton
model VmInstanceHybridIdentityMetadata
is ProxyResource {
// TODO/NOTE: key name is used as a workaround for name collision with singleton
/** Name of the VM Instance Hybrid Identity Metadata */
@key
@segment("hybridIdentityMetadata")
@path
@visibility("read")
name: string;
}
```
This should be allowed, since the key name is not transposed into the route by virtue of both being a singleton, but this actually produces an error:
```
Resource type 'VmInstanceHybridIdentityMetadata' has a key property named 'name' which conflicts with the key name of a parent or child resource.TypeSpec(@typespec/rest/duplicate-parent-key)
```
The workaround is to add a phony key name to the child resource to disambiguate the keys, like `@key("vmHybridIdentityMetadataName")`.
Contributor guide
Assessment
This issue has not been assessed yet.