Skip to content

Commit 7005c50

Browse files
iscai-msftiscai-msftCopilot
authored
feat(http-specs): add test for operation body params with reserved names (#10529)
## Summary Add a Spector scenario to verify that operation parameters whose names match Python Mapping protocol methods (e.g., `items`) are sent with the original name on the wire, not mangled (e.g., to `items_property`). Fixes #10247 ## Changes - **`main.tsp`**: Added `ReservedOperationBodyParams` namespace with `withItems(items: string[]): void` operation - **`mockapi.ts`**: Mock expects `POST /special-words/operations/body-param-reserved` with body `{"items": ["item"]}` - **`spec-summary.md`**: Auto-regenerated ## Labels `lib:http-specs` --------- Co-authored-by: iscai-msft <isabellavcai@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 930117b commit 7005c50

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: feature
3+
packages:
4+
- "@typespec/http-specs"
5+
---
6+
7+
Add test scenario for operation body parameters with reserved names (e.g., `items`) to verify wire name is not mangled.

packages/http-specs/spec-summary.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5166,6 +5166,19 @@ Verify that the name "with" works. Send this parameter to pass with value `ok`.
51665166

51675167
Verify that the name "yield" works. Send this parameter to pass with value `ok`.
51685168

5169+
### SpecialWords_ReservedOperationBodyParams_withItems
5170+
5171+
- Endpoint: `post /special-words/operations/body-param-reserved`
5172+
5173+
Verify that an operation parameter named "items" is sent with the key "items" on the wire,
5174+
not mangled to "items_property" or similar.
5175+
5176+
Send
5177+
5178+
```json
5179+
{ "items": ["item"] }
5180+
```
5181+
51695182
### Streaming_Jsonl_Basic_receive
51705183

51715184
- Endpoint: `get /streaming/jsonl/basic/receive`

packages/http-specs/specs/special-words/main.tsp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,28 @@ namespace ModelProperties {
290290
op withList(@body body: ModelWithList): void;
291291
}
292292

293+
/**
294+
* Verify that operation parameters whose names match Python Mapping protocol methods
295+
* (e.g., items, keys, values) are sent with the original name on the wire, not mangled.
296+
*/
297+
@route("/operations")
298+
namespace ReservedOperationBodyParams {
299+
@scenario
300+
@scenarioDoc("""
301+
Verify that an operation parameter named "items" is sent with the key "items" on the wire,
302+
not mangled to "items_property" or similar.
303+
304+
Send
305+
306+
```json
307+
{"items": ["item"]}
308+
```
309+
""")
310+
@post
311+
@route("/body-param-reserved")
312+
op withItems(items: string[]): void;
313+
}
314+
293315
/**
294316
* Verify enum member names that are special words.
295317
*/

packages/http-specs/specs/special-words/mockapi.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ Scenarios.SpecialWords_Parameters_cancellationToken = createParametersTests(
420420
"cancellationToken",
421421
);
422422

423+
Scenarios.SpecialWords_ReservedOperationBodyParams_withItems = passOnSuccess({
424+
uri: "/special-words/operations/body-param-reserved",
425+
method: "post",
426+
request: {
427+
body: json({
428+
items: ["item"],
429+
}),
430+
},
431+
response: {
432+
status: 204,
433+
},
434+
kind: "MockApiDefinition",
435+
});
436+
423437
Scenarios.SpecialWords_ExtensibleStrings_putExtensibleStringValue = passOnSuccess({
424438
uri: `/special-words/extensible-strings/string`,
425439
method: "put",

0 commit comments

Comments
 (0)