Skip to content

Commit

Permalink
fix @clientName validation for operation within interface (#1205) (#…
Browse files Browse the repository at this point in the history
…1222)

Fix operation client name validation introduced in
#1119
  • Loading branch information
live1206 committed Jul 23, 2024
1 parent 524d459 commit 5f6e78a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/operation-validation-2024-6-19-18-35-46.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

Fix `@clientName` conflict validation that operation defined within an interface
5 changes: 5 additions & 0 deletions packages/typespec-client-generator-core/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ function validateClientNamesPerNamespace(
// Check for duplicate client names for operations
validateClientNamesCore(tcgcContext, scope, namespace.operations.values());

// check for duplicate client names for operations in interfaces
for (const item of namespace.interfaces.values()) {
validateClientNamesCore(tcgcContext, scope, item.operations.values());
}

// Check for duplicate client names for interfaces
validateClientNamesCore(tcgcContext, scope, namespace.interfaces.values());

Expand Down
30 changes: 30 additions & 0 deletions packages/typespec-client-generator-core/test/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,36 @@ describe("typespec-client-generator-core: decorators", () => {
]);
});

it("duplicate operation in interface with all language scopes", async () => {
const diagnostics = await runner.diagnose(
`
@service
namespace Contoso.WidgetManager;
interface C {
@clientName("b")
@route("/a")
op a(): void;
@route("/b")
op b(): void;
}
`
);

expectDiagnostics(diagnostics, [
{
code: "@azure-tools/typespec-client-generator-core/duplicate-client-name",
message: 'Client name: "b" is duplicated in language scope: "AllScopes"',
},
{
code: "@azure-tools/typespec-client-generator-core/duplicate-client-name",
message:
'Client name: "b" is defined somewhere causing nameing conflicts in language scope: "AllScopes"',
},
]);
});

it("duplicate scalar with all language scopes", async () => {
const diagnostics = await runner.diagnose(
`
Expand Down

0 comments on commit 5f6e78a

Please sign in to comment.