Skip to content

Commit

Permalink
Merge branch 'release/september-2024' into change-response-to-be-array
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Sep 19, 2024
2 parents b9e6a64 + 354be86 commit eb723b4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

handle orphan types in nested namespaces
27 changes: 16 additions & 11 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1843,17 +1843,22 @@ export function getAllModelsWithDiagnostics(
}
// update for orphan models/enums/unions
for (const client of listClients(context)) {
// orphan models
for (const model of client.service.models.values()) {
diagnostics.pipe(handleServiceOrphanType(context, model));
}
// orphan enums
for (const enumType of client.service.enums.values()) {
diagnostics.pipe(handleServiceOrphanType(context, enumType));
}
// orphan unions
for (const unionType of client.service.unions.values()) {
diagnostics.pipe(handleServiceOrphanType(context, unionType));
const namespaces = [client.service];
while (namespaces.length) {
const namespace = namespaces.pop()!;
// orphan models
for (const model of namespace.models.values()) {
diagnostics.pipe(handleServiceOrphanType(context, model));
}
// orphan enums
for (const enumType of namespace.enums.values()) {
diagnostics.pipe(handleServiceOrphanType(context, enumType));
}
// orphan unions
for (const unionType of namespace.unions.values()) {
diagnostics.pipe(handleServiceOrphanType(context, unionType));
}
namespaces.push(...namespace.namespaces.values());
}
}
// update access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,28 @@ describe("typespec-client-generator-core: @usage", () => {
code: "@azure-tools/typespec-client-generator-core/conflict-usage-override",
});
});

it("orphan model in group", async () => {
await runner.compileWithBuiltInService(
`
@access(Access.public)
@usage(Usage.output)
namespace Models {
model Model1 {
ref: Model2;
}
model Model2 {
name: string;
}
}
`
);
const models = runner.context.sdkPackage.models;
strictEqual(models.length, 2);
strictEqual(models[0].usage, UsageFlags.Output);
strictEqual(models[0].access, "public");
strictEqual(models[1].usage, UsageFlags.Output);
strictEqual(models[1].access, "public");
});
});

0 comments on commit eb723b4

Please sign in to comment.