Azure / Azure/typespec-azure

[Bug]: Unexpected @typespec/openapi/duplicate-type-name error thrown

Open
#2,937 1 comment 0 reactions 0 assignees View on GitHub
bug emitter:autorest
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

### Describe the bug

@typespec/openapi/duplicate-type-name is thrown unexpectedly in the provided playground when unioning the `Response` type param of `ArmResourceActionAsync`:
```
validateStack is ArmResourceActionAsync<
DeploymentStack,
DeploymentStack,
Response = ArmResponse | ValidationBadRequestResponse,
BaseParameters = TBaseParams,
>;
```

The interface this is declared in has multiple instances (per resource scope, since we share the same model per scope). The first interface `DeploymentStacksAtResourceGroup` does not have this error, but the other interfaces below it do.

Removing the union fixes the error. The error is confusing to me because these response types are not really open API "definitions". They get inlined into the "responses: { [statusCode]: { }}` object in the final output.

My goal is to add a `x-ms-error-response: false` 400 response to this action which indicates the user submitted a bad entity. I believe current SDK clients do not throw exceptions on this response status code as a result of `x-ms-error-response: false` in the non-typespec Open API swagger.

I worked around this issue by instead passing
```
Response = ArmResponse,
Error = ErrorResponse | ValidationBadRequestResponse
```

### Reproduction

Playground: https://azure.github.io/typespec-azure/playground/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdNUZdmVyc2lvbmluZ8wfYXp1cmUtdG9vbHMvyCstxhVjb3Jl3yvIK3Jlc291cmNlLW1hbmFnZXIiOwoKdXNpbmcgSHR0cDvHDFJlc3TIDFbpAI7IEkHESi5Db3JlzhJSx1xNxlvdHS5Gb3VuZGF0aW9uczsKCkBzZXJ2aWNlKCN7IHRpdGxlOiAiRGVwbG95bWVudFN0YWNrc0NsaWVudCIgfSkKQGFybUNvbW1vblTkAN%2FnAKMo1mrLKS7HKnMudjUpCkB1c2VEZXBlbmRlbmN51z7KMjFfMF9QcmV2aWV3XzHXPuQBFdozbmFtZXNwYWNlIFTlAWEKbW9kZWwg7wDpIGV4dGVuZHP3ATlUcmFja2VkyBc8e8VNOiBzdHLkAW59Pgp7Cgp911xWYWxpZGF0ZVJlc3VsdMcqQGRvYygiyFEgdsYkaW9uIGZhaWxlZC4iKcdOxz9pb25CYWRSZXF1ZXN0UmVzcG9uc2U8VEJvZHk%2BIHsKICAuLi7SITsKCiAgxmxUaGUgYm9keSDkAp4gb2YgdGhlIG9wZXLGd3LGOSBvciByxz3kAIQgIEDENVJvb3QKIMVAOiDFdTvkAMZpbnRlcmbkAV3vAPTmAgBPcHM8VEJhc2VQYXJhbXPpAWXkAhhTcGVjLlJlZmxlY%2BQAgC5N5ADt5gDKLyoqCiAgICogUnVucyBwcmVmbGlnaHTsASVvbuUAv8p2IHPEdyB0ZW1wbGF0ZSBhdMUh5AOGaWZpZWQgc2NvcGUgdG8gdmVyaWZ5IGl0cyBhY2NlcHRhbmPFGeUB%2B%2BQDh%2BYBk%2BgB%2FOUAiy%2FkAQlh5QCqKCLnAIhl5QEfyA3mAkdpcyBBcm3IREHFMUFzeW5jPMRH8AEmLNoV6AHBID3HUcUOPP0CWz4gfP4CLt4%2BxnnpAa9ldGVycyA9IOsBwQogID7lAfjkBAzoAOVP6AJDc%2FoCD3NB5ACFxS9Hcm91cOkCCvkCN80v7gCUPiB7fQr%2FAIT2AITfd3BzPFN1YnNjcmlwxEzTdg%3D%3D&e=%40azure-tools%2Ftypespec-autorest&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40azure-tools%2Ftypespec-azure-rulesets%2Fresource-manager%22%5D%7D%7D

### 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 linked playground reproduction and the @typespec/openapi duplicate-type-name diagnostic, comparing the unioned Response form with the Error parameter workaround. Trace how the repeated ArmResourceActionAsync interfaces are emitted and verify that the intended 400 response with x-ms-error-response: false is produced without the diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.