diff --git a/.chronus/changes/spector-new-case-2025-10-18-7-0-48.md b/.chronus/changes/spector-new-case-2025-10-18-7-0-48.md new file mode 100644 index 00000000000..50498f86a84 --- /dev/null +++ b/.chronus/changes/spector-new-case-2025-10-18-7-0-48.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/http-specs" +--- + +Add test case for special words about model property name \ No newline at end of file diff --git a/packages/http-specs/spec-summary.md b/packages/http-specs/spec-summary.md index 34bae138631..082812f7ef7 100644 --- a/packages/http-specs/spec-summary.md +++ b/packages/http-specs/spec-summary.md @@ -3392,6 +3392,29 @@ Expected header parameters: Check we recognize Repeatability-Request-ID and Repeatability-First-Sent. +### SpecialWords_ModelProperties_dictMethods + +- Endpoint: `get /special-words/model-properties/dict-methods` + +Verify that model properties can use names that are Python dict methods. These names (keys, items, values, etc.) may conflict with Python's dict class methods. + +Send + +```json +{ + "keys": "ok", + "items": "ok", + "values": "ok", + "popitem": "ok", + "clear": "ok", + "update": "ok", + "setdefault": "ok", + "pop": "ok", + "get": "ok", + "copy": "ok" +} +``` + ### SpecialWords_ModelProperties_sameAsModel - Endpoint: `get /special-words/model-properties/same-as-model` diff --git a/packages/http-specs/specs/special-words/main.tsp b/packages/http-specs/specs/special-words/main.tsp index 7517d04be5a..2705d858905 100644 --- a/packages/http-specs/specs/special-words/main.tsp +++ b/packages/http-specs/specs/special-words/main.tsp @@ -231,4 +231,42 @@ namespace ModelProperties { """) @route("same-as-model") op sameAsModel(@body body: SameAsModel): void; + + // Python dict method names that could conflict + model DictMethods { + keys: string; + items: string; + values: string; + popitem: string; + clear: string; + update: string; + setdefault: string; + pop: string; + get: string; + copy: string; + } + + @scenario + @scenarioDoc(""" + Verify that model properties can use names that are Python dict methods. These names (keys, items, values, etc.) may conflict with Python's dict class methods. + + Send + + ```json + { + "keys": "ok", + "items": "ok", + "values": "ok", + "popitem": "ok", + "clear": "ok", + "update": "ok", + "setdefault": "ok", + "pop": "ok", + "get": "ok", + "copy": "ok" + } + ``` + """) + @route("dict-methods") + op dictMethods(@body body: DictMethods): void; } diff --git a/packages/http-specs/specs/special-words/mockapi.ts b/packages/http-specs/specs/special-words/mockapi.ts index 6c85d72cb9c..4d2883b10f1 100644 --- a/packages/http-specs/specs/special-words/mockapi.ts +++ b/packages/http-specs/specs/special-words/mockapi.ts @@ -16,6 +16,29 @@ Scenarios.SpecialWords_ModelProperties_sameAsModel = passOnSuccess({ kind: "MockApiDefinition", }); +Scenarios.SpecialWords_ModelProperties_dictMethods = passOnSuccess({ + uri: "/special-words/model-properties/dict-methods", + method: "post", + request: { + body: json({ + keys: "ok", + items: "ok", + values: "ok", + popitem: "ok", + clear: "ok", + update: "ok", + setdefault: "ok", + pop: "ok", + get: "ok", + copy: "ok", + }), + }, + response: { + status: 204, + }, + kind: "MockApiDefinition", +}); + function createModelsTests(uri: string) { return passOnSuccess({ uri,