Skip to content

Commit e8aae30

Browse files
iscai-msftiscai-msftCopilot
authored
[tcgc] fix path in override (#4644)
fixes #4257 --------- Co-authored-by: iscai-msft <isabellavcai@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b7123b1 commit e8aae30

4 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@azure-tools/typespec-client-generator-core"
5+
---
6+
7+
Verify all `@path` parameters are present in override

packages/typespec-client-generator-core/src/decorators.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
getServers,
3333
isBody,
3434
isBodyRoot,
35+
isPathParam,
3536
} from "@typespec/http";
3637
import { getVersion, resolveVersions, type Version } from "@typespec/versioning";
3738
import {
@@ -749,6 +750,24 @@ export const $override = (
749750
}
750751
}
751752

753+
// Warn if original param has @path but override param doesn't,
754+
// unless any override param has @clientLocation (indicating an intentional customization
755+
// where non-path params are just pass-throughs)
756+
if (
757+
isPathParam(context.program, originalParam) &&
758+
!isPathParam(context.program, overrideParams[index]) &&
759+
!overrideParams.some((p) => p.decorators.some((d) => d.decorator.name === "$clientLocation"))
760+
) {
761+
reportDiagnostic(context.program, {
762+
code: "override-parameters-mismatch",
763+
target: context.decoratorTarget,
764+
format: {
765+
methodName: original.name,
766+
checkParameter: overrideParams[index].name,
767+
},
768+
});
769+
}
770+
752771
// Apply the alternate type to the original parameter
753772
const overrideParam = overrideParams[index];
754773
overrideParam.decorators

packages/typespec-client-generator-core/src/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ function getSdkHttpParameters(
417417
(segment) => segment[segment.length - 1],
418418
);
419419
}
420+
420421
return diagnostics.wrap(retval);
421422
}
422423

packages/typespec-client-generator-core/test/decorators/override.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,30 @@ it("remove optional query param and add secret name", async () => {
547547
strictEqual(maxResultsParam.name, "maxresults");
548548
});
549549

550+
it("reports diagnostic when override parameter is missing @path", async () => {
551+
const [_, diagnostics] = await SimpleBaseTester.compileAndDiagnose(
552+
createClientCustomizationInput(
553+
`
554+
@service
555+
namespace MyService;
556+
557+
@route("/items/{itemId}")
558+
op getItem(@path itemId: string): void;
559+
`,
560+
`
561+
namespace MyCustomizations;
562+
563+
op getItemOverride(itemId: string): void;
564+
565+
@@override(MyService.getItem, MyCustomizations.getItemOverride);
566+
`,
567+
),
568+
);
569+
expectDiagnostics(diagnostics, {
570+
code: "@azure-tools/typespec-client-generator-core/override-parameters-mismatch",
571+
});
572+
});
573+
550574
describe("@clientName", () => {
551575
it("original method", async () => {
552576
const { program } = await SimpleBaseTester.compile(

0 commit comments

Comments
 (0)