Skip to content

Commit

Permalink
Fixes #684.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Apr 29, 2024
1 parent 74a3d6c commit 57b0329
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export const rpcOperationRequestBodyRule = createRule({
operation.namespace?.namespace?.name === "Azure"
) {
const httpOperation = getHttpOperation(context.program, originalOperation)[0];
const bodyParam = httpOperation.parameters.body;
const verb = httpOperation.verb.toLowerCase();
if (verb === "get" || verb === "delete") {
if ((verb === "get" || verb === "delete") && bodyParam !== undefined) {
context.reportDiagnostic({
target: originalOperation,
messageId: "noBodyAllowed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ describe("typespec-azure-core: rpc-operation-request-body", () => {
);
});

it("allow RPCOperation with `@get` and empty body", async () => {
await tester
.expect(
`
model Widget {
name: string;
}
@get
@route ("/")
op getWidget is RpcOperation<{}, Widget>;
`
)
.toBeValid();
});

it("allow RPCOperation with `@delete` and empty body", async () => {
await tester
.expect(
`
model Widget {
name: string;
}
@delete
@route ("/")
op deleteWidget is RpcOperation<{}, Widget>;
`
)
.toBeValid();
});

it("emits warning when RPCOperation is marked with `@get` and has a request body", async () => {
await tester
.expect(
Expand Down

0 comments on commit 57b0329

Please sign in to comment.