Azure / Azure/typespec-azure

[Bug]: Renaming resource not working properly

Open
#2,551 1 comment 0 reactions 0 assignees View on GitHub
design:needed lib:azure-core lib:azure-resource-manager
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

### Describe the bug

I have a scenario where I'm renaming a tracked resource X to Y a new API version. The way I thought about doing this is by leveraging @added and @removed decorators.

However, X has a child resource Z, that now needs to be a child resource of Y But if I do something like this it gives conflict error. How can I unblock this scenario?

### Reproduction

TypeScript

```tsp
@added(Versions.`V1`)
@removed(Versions.`V2`)
@parentResource(X)
model Z is ProxyResource {
...ResourceNameParameter<
Occurrence,
KeyName = "Id",
NamePattern = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
>;
}

@added(Versions.`V2`)
@parentResource(Y)
model Zis ProxyResource {
...ResourceNameParameter<
Occurrence,
KeyName = "Id",
NamePattern = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
>;
}
```

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/azure/typespec-azure/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that this issue is about the Azure libraries for typespec. For bug in the typespec language or core libraries file it in the [TypeSpec repo](https://github.com/Microsoft/TypeSpec/issues/new/choose)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Research direction

Start with the TypeSpec reproduction in the issue and inspect the conflict produced by the two Z declarations using @added, @removed, and @parentResource. Trace how the resource transition from X to Y is validated; done means the reported rename scenario is resolved or its supported limitation and workaround are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.