Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
57 changes: 57 additions & 0 deletions packages/http-specs/specs/special-words/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
21 changes: 20 additions & 1 deletion packages/http-specs/specs/special-words/mockapi.ts
Original file line number Diff line number Diff line change
@@ -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<string, ScenarioMockApi> = {};

Expand Down Expand Up @@ -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",
});