Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

Add spector case for extensible enum with special word member names
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_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`
Expand Down
55 changes: 55 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,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;
}
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_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",
});
Loading