Skip to content

Commit 94bdba5

Browse files
tadeleshqiaozha
andauthored
[tcgc] Change listRawSubClients from DFS to BFS. (#2389)
do not break the model sequence. cc: @qiaozha --------- Co-authored-by: Qiaoqiao Zhang <[email protected]>
1 parent 48f37bb commit 94bdba5

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@azure-tools/typespec-client-generator-core"
5+
---
6+
7+
Change `listRawSubClients` from DFS to BFS.

packages/typespec-client-generator-core/src/internal-utils.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -675,18 +675,15 @@ export function handleVersioningMutationForGlobalNamespace(context: TCGCContext)
675675
export function listRawSubClients(
676676
context: TCGCContext,
677677
client: SdkOperationGroup | SdkClient,
678-
retval?: (SdkOperationGroup | SdkClient)[],
679-
): (SdkOperationGroup | SdkClient)[] {
680-
if (retval === undefined) {
681-
retval = [];
682-
}
683-
if (retval.includes(client)) return retval;
684-
if (client.kind === "SdkOperationGroup") {
685-
retval.push(client);
686-
}
687-
688-
for (const operationGroup of listOperationGroups(context, client)) {
689-
listRawSubClients(context, operationGroup, retval);
678+
): SdkOperationGroup[] {
679+
const retval: SdkOperationGroup[] = [];
680+
const queue: SdkOperationGroup[] = listOperationGroups(context, client);
681+
while (queue.length > 0) {
682+
const operationGroup = queue.pop()!;
683+
retval.push(operationGroup);
684+
if (operationGroup.subOperationGroups) {
685+
queue.push(...operationGroup.subOperationGroups);
686+
}
690687
}
691688
return retval;
692689
}

0 commit comments

Comments
 (0)