diff --git a/packages/http-specs/spec-summary.md b/packages/http-specs/spec-summary.md index 418dbf7eafa..d058ef3fb5a 100644 --- a/packages/http-specs/spec-summary.md +++ b/packages/http-specs/spec-summary.md @@ -3977,6 +3977,13 @@ Expected header parameters: Check we recognize Repeatability-Request-ID and Repeatability-First-Sent. +### SpecialWords_Enums_putEnumValue + +- Endpoint: `put /special-words/enums/string` + +Verify that enum members with special word names can be sent and received properly. +Send 'class' and expect the same value back. + ### SpecialWords_ModelProperties_dictMethods - Endpoint: `get /special-words/model-properties/dict-methods` diff --git a/packages/http-specs/specs/special-words/main.tsp b/packages/http-specs/specs/special-words/main.tsp index a48f1a3f257..df03b05e4b2 100644 --- a/packages/http-specs/specs/special-words/main.tsp +++ b/packages/http-specs/specs/special-words/main.tsp @@ -289,3 +289,60 @@ namespace ModelProperties { @route("list") op withList(@body body: ModelWithList): void; } + +/** + * Verify enum member names that are special words using extensible enum (union). + */ +union Enum { + string, + and: "and", + as: "as", + assert: "assert", + async: "async", + await: "await", + break: "break", + class: "class", + constructor: "constructor", + continue: "continue", + def: "def", + del: "del", + elif: "elif", + `else`: "else", + except: "except", + exec: "exec", + finally: "finally", + for: "for", + from: "from", + global: "global", + `if`: "if", + `import`: "import", + in: "in", + `is`: "is", + lambda: "lambda", + not: "not", + or: "or", + pass: "pass", + raise: "raise", + `return`: "return", + try: "try", + while: "while", + with: "with", + yield: "yield", +} + +/** + * Verify enum member names that are special words. + */ +@route("/enums") +interface Enums { + @scenario + @scenarioDoc(""" + Verify that enum members with special word names can be sent and received properly. + Send 'class' and expect the same value back. + """) + @put + @route("/string") + putEnumValue(@body body: Enum): { + @body body: Enum; + }; +} diff --git a/packages/http-specs/specs/special-words/mockapi.ts b/packages/http-specs/specs/special-words/mockapi.ts index 8076c8b7d4c..cd8389f7ff1 100644 --- a/packages/http-specs/specs/special-words/mockapi.ts +++ b/packages/http-specs/specs/special-words/mockapi.ts @@ -1,4 +1,4 @@ -import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; +import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; export const Scenarios: Record = {}; @@ -419,3 +419,22 @@ Scenarios.SpecialWords_Parameters_cancellationToken = createParametersTests( }, "cancellationToken", ); + +Scenarios.SpecialWords_Enums_putEnumValue = passOnSuccess({ + uri: `/special-words/enums/string`, + method: "put", + request: { + body: json("class"), + }, + response: { + status: 200, + body: json("class"), + }, + handler: (req: MockRequest) => { + return { + status: 200, + body: json(req.body), + }; + }, + kind: "MockApiDefinition", +});