Skip to content

Commit 1dddaa9

Browse files
Copilotmsyyc
andauthored
Add test case for model property named "list" (#9259)
Adds test coverage for model properties using reserved keywords, specifically "list" which is reserved in Python and other languages. ## Changes - **`main.tsp`**: Added `ModelWithList` model with `list` property in `ModelProperties` namespace, following existing pattern for reserved word testing - **`mockapi.ts`**: Added `SpecialWords_ModelProperties_withList` scenario expecting `{"list": "ok"}` payload - **Special words list**: Updated documentation to include "list" in the enumerated reserved words ## Example ```typespec model ModelWithList { list: string; } @Scenario @route("list") op withList(@Body body: ModelWithList): void; ``` Validates that generators properly escape or handle the `list` property name when generating client code. > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `telemetry.astro.build` > - Triggering command: `/usr/local/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build sh n-sc�� ebsite/src/content/docs/docs/emitters/openapi3/reference node k/typespec/typespec/node_modules../../website/src/content/docs/docs/emitters/protobuf/reference -p . n-schema/referentspd doc . --enable-experimental --output-dir ../../website/src/content/docs/docs/emitters/servers/http-server-csharp/reference --skip-js node tool�� lmstxt --output-dir ../../website/src/content/docs/docs/libraries/http/reference node pec/node_modules/.bin/sh /library-linter sh sh /.bin/sh sh` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/microsoft/typespec/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[specs] new test case for model whose property is named "list"</issue_title> > <issue_description>To cover scenario #9248, we need a new test case in https://github.com/microsoft/typespec/blob/main/packages/http-specs/specs/special-words/main.tsp that it has model property named "list" > > NOTE: > - DO add changelog in https://github.com/microsoft/typespec/tree/main/.chronus/changes > - DO run command https://github.com/microsoft/typespec/blob/664978b3cf7399e43e2823d3a69043203e740109/packages/http-specs/package.json#L14 under https://github.com/microsoft/typespec/blob/main/packages/http-specs to check all ci items.</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #9258 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
1 parent 3d25601 commit 1dddaa9

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-specs"
5+
---
6+
7+
Add test case for model property named "list" to cover special word scenarios

packages/http-specs/spec-summary.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,18 @@ Send
36213621
{ "SameAsModel": "ok" }
36223622
```
36233623

3624+
### SpecialWords_ModelProperties_withList
3625+
3626+
- Endpoint: `get /special-words/model-properties/list`
3627+
3628+
Verify that a property can be named "list", which is a reserved word in many languages like Python.
3629+
3630+
Send
3631+
3632+
```json
3633+
{ "list": "ok" }
3634+
```
3635+
36243636
### SpecialWords_Models_and
36253637

36263638
- Endpoint: `get /special-words/models/and`

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ using Spector;
3434
* in
3535
* is
3636
* lambda
37+
* list
3738
* not
3839
* or
3940
* pass
@@ -269,4 +270,22 @@ namespace ModelProperties {
269270
""")
270271
@route("dict-methods")
271272
op dictMethods(@body body: DictMethods): void;
273+
274+
// Test for model property named "list" which is a reserved word in many languages
275+
model ModelWithList {
276+
list: string;
277+
}
278+
279+
@scenario
280+
@scenarioDoc("""
281+
Verify that a property can be named "list", which is a reserved word in many languages like Python.
282+
283+
Send
284+
285+
```json
286+
{"list": "ok"}
287+
```
288+
""")
289+
@route("list")
290+
op withList(@body body: ModelWithList): void;
272291
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ Scenarios.SpecialWords_ModelProperties_dictMethods = passOnSuccess({
3939
kind: "MockApiDefinition",
4040
});
4141

42+
Scenarios.SpecialWords_ModelProperties_withList = passOnSuccess({
43+
uri: "/special-words/model-properties/list",
44+
method: "post",
45+
request: {
46+
body: json({
47+
list: "ok",
48+
}),
49+
},
50+
response: {
51+
status: 204,
52+
},
53+
kind: "MockApiDefinition",
54+
});
55+
4256
function createModelsTests(uri: string) {
4357
return passOnSuccess({
4458
uri,

0 commit comments

Comments
 (0)