-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1453 This is a breaking change in TCGC, but there are some reasons of making this change: 1. The `HttpOperation.responses` from typespec core library also defines as an array. 2. The type `Map` is not persistable in typescript, which causes issues in some emitter implementation such as dotnet, because it needs to serialize everything in TCGC output and sends it to the generator written in other language (details [here](Azure/autorest.csharp#5028)) 3. In most cases, we have no more than 4 responses corresponding different status codes. In the majority of cases, we have 2 or 1. In such a small collections, maps do not have distinguishable performance improvement comparing with arrays with `find`, and arrays have the advantages above.
- Loading branch information
1 parent
354be86
commit 8adc5b1
Showing
11 changed files
with
325 additions
and
249 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
.chronus/changes/change-response-to-be-array-2024-8-14-11-27-13.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
changeKind: breaking | ||
packages: | ||
- "@azure-tools/typespec-client-generator-core" | ||
--- | ||
|
||
1. The type of `responses` and `exceptions` in `SdkHttpOperation` changed from `Map<number | HttpStatusCodeRange | "*", SdkHttpResponse>` to `SdkHttpResponse[]`. | ||
2. The type of `responses` in `SdkHttpOperationExample` changed from `Map<number, SdkHttpResponseExampleValue>` to `SdkHttpResponseExampleValue[]`. | ||
3. `SdkHttpResponse` adds a new property `statusCodes` to store its corresponding status code or status code range. | ||
|
||
Migration hints: | ||
The type changed from map to array, and the key of the map is moved as a new property of the value type. For example, for code like this: | ||
``` | ||
for (const [statusCodes, response] of operation.responses) | ||
``` | ||
you could do the same in this way: | ||
``` | ||
for (const response of operation.responses) | ||
{ | ||
const statusCodes = response.statusCodes; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.