Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tcgc] handle orphan types in nested namespaces #1558

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
});
Loading