Azure / Azure/typespec-azure

Key name collisions are detected when a singleton resource is parented to another singleton resource.

Open
#182 1 comment 0 reactions 0 assignees View on GitHub
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

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.