diff --git a/.chronus/changes/copilot-add-special-words-enum-2026-02-26-12-04-50.md b/.chronus/changes/copilot-add-special-words-enum-2026-02-26-12-04-50.md new file mode 100644 index 00000000000..275564f4140 --- /dev/null +++ b/.chronus/changes/copilot-add-special-words-enum-2026-02-26-12-04-50.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/http-specs" +--- + +Add spector case for extensible enum with special word member names diff --git a/packages/http-specs/spec-summary.md b/packages/http-specs/spec-summary.md index 418dbf7eafa..c68a503c558 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_ExtensibleStrings_putExtensibleStringValue + +- Endpoint: `put /special-words/extensible-strings/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..e69f36b51b2 100644 --- a/packages/http-specs/specs/special-words/main.tsp +++ b/packages/http-specs/specs/special-words/main.tsp @@ -289,3 +289,58 @@ namespace ModelProperties { @route("list") op withList(@body body: ModelWithList): void; } + +/** + * Verify enum member names that are special words using extensible enum (union). + */ +union ExtensibleString { + 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("/extensible-strings") +interface ExtensibleStrings { + @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") + putExtensibleStringValue(@body body: ExtensibleString): ExtensibleString; +} diff --git a/packages/http-specs/specs/special-words/mockapi.ts b/packages/http-specs/specs/special-words/mockapi.ts index 8076c8b7d4c..28392c29899 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_ExtensibleStrings_putExtensibleStringValue = passOnSuccess({ + uri: `/special-words/extensible-strings/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", +});