forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow overriding base operation verb (microsoft#3717)
fix microsoft#3636 [Playground example](https://cadlplayground.z22.web.core.windows.net/prs/3717/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwOwpAc2VydmljZQpuYW1lc3BhY2UgRGVtb1PGFjsKCi8vIFRoaXMgc2hvdWxkIGJlIGFuIGVycm9yCkByb3V0ZSgiMSIpCkBnZXTGBW9wIG9wMSgpOiB2b2lk30LHQjLJQnBvc8dDMstDxBwgb3AgQmFzZTxUPsQaVMZaTm8gd2FybuQA2mhlcmXJUjQiKSDFTcQ3b3ZlcnJpZGUgaXPGQ3N0cmluZz47Cg%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40typespec%2Fhttp%2Fall%22%5D%7D%7D)
- Loading branch information
1 parent
f3c2c9b
commit ce10ed9
Showing
4 changed files
with
81 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking | ||
changeKind: feature | ||
packages: | ||
- "@typespec/http" | ||
--- | ||
|
||
Allow overriding base operation verb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expectDiagnostics } from "@typespec/compiler/testing"; | ||
import { describe, expect, it } from "vitest"; | ||
import { diagnoseOperations, getRoutesFor } from "./test-host.js"; | ||
|
||
describe("specify verb with each decorator", () => { | ||
it.each([ | ||
["@get", "get"], | ||
["@post", "post"], | ||
["@put", "put"], | ||
["@patch", "patch"], | ||
["@delete", "delete"], | ||
["@head", "head"], | ||
])("%s set verb to %s", async (dec, expected) => { | ||
const routes = await getRoutesFor(`${dec} op test(): string;`); | ||
expect(routes[0].verb).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe("emit error when using 2 verb decorator together on the same node", () => { | ||
it.each([ | ||
["@get", "@post"], | ||
["@post", "@put"], | ||
])("%s", async (...decs) => { | ||
const diagnostics = await diagnoseOperations(`${decs.join(" ")} op test(): string;`); | ||
const diag = { | ||
code: "@typespec/http/http-verb-duplicate", | ||
message: "HTTP verb already applied to test", | ||
}; | ||
expectDiagnostics(diagnostics, new Array(decs.length).fill(diag)); | ||
}); | ||
}); | ||
|
||
it("allow overriding the verb specified in a base operation", async () => { | ||
const routes = await getRoutesFor(` | ||
@get op test<T>(): T; | ||
@head op ping is test<void>; | ||
`); | ||
expect(routes[0].verb).toBe("head"); | ||
}); |