Skip to content
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"
---

Verify all `@path` parameters are present in override
19 changes: 19 additions & 0 deletions packages/typespec-client-generator-core/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getServers,
isBody,
isBodyRoot,
isPathParam,
} from "@typespec/http";
import { getVersion, resolveVersions, type Version } from "@typespec/versioning";
import {
Expand Down Expand Up @@ -749,6 +750,24 @@ export const $override = (
}
}

// Warn if original param has @path but override param doesn't,
// unless any override param has @clientLocation (indicating an intentional customization
// where non-path params are just pass-throughs)
if (
isPathParam(context.program, originalParam) &&
!isPathParam(context.program, overrideParams[index]) &&
!overrideParams.some((p) => p.decorators.some((d) => d.decorator.name === "$clientLocation"))
) {
reportDiagnostic(context.program, {
code: "override-parameters-mismatch",
target: context.decoratorTarget,
format: {
methodName: original.name,
checkParameter: overrideParams[index].name,
},
});
}

// Apply the alternate type to the original parameter
const overrideParam = overrideParams[index];
overrideParam.decorators
Expand Down
1 change: 1 addition & 0 deletions packages/typespec-client-generator-core/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ function getSdkHttpParameters(
(segment) => segment[segment.length - 1],
);
}

return diagnostics.wrap(retval);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,30 @@ it("remove optional query param and add secret name", async () => {
strictEqual(maxResultsParam.name, "maxresults");
});

it("reports diagnostic when override parameter is missing @path", async () => {
const [_, diagnostics] = await SimpleBaseTester.compileAndDiagnose(
createClientCustomizationInput(
`
@service
namespace MyService;

@route("/items/{itemId}")
op getItem(@path itemId: string): void;
`,
`
namespace MyCustomizations;

op getItemOverride(itemId: string): void;

@@override(MyService.getItem, MyCustomizations.getItemOverride);
`,
),
);
expectDiagnostics(diagnostics, {
code: "@azure-tools/typespec-client-generator-core/override-parameters-mismatch",
});
});

describe("@clientName", () => {
it("original method", async () => {
const { program } = await SimpleBaseTester.compile(
Expand Down
Loading