-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'spector-jsonl' of github.com:microsoft/typespec into sp…
…ector-jsonl
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import "@typespec/http"; | ||
import "@typespec/http/streams"; | ||
import "@typespec/spector"; | ||
|
||
using Http; | ||
using Http.Streams; | ||
using Spector; | ||
|
||
@doc("Test of jsonl stream.") | ||
@scenarioService("/stream/jsonl") | ||
namespace Stream.Jsonl; | ||
|
||
@scenario | ||
@scenarioDoc(""" | ||
Basic case of jsonl stream. | ||
""") | ||
@route("basic") | ||
namespace Basic { | ||
@route("send") | ||
@post | ||
op send(stream: JsonlStream<Info>): NoContentResponse; | ||
|
||
@route("receive") | ||
op receive(): JsonlStream<Info>; | ||
|
||
model Info { | ||
desc: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; | ||
|
||
export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
||
Scenarios.Stream_Jsonl_send = passOnSuccess({ | ||
uri: "/stream/jsonl/send", | ||
method: "post", | ||
request: { | ||
headers: { | ||
"Content-Type": "application/jsonl", | ||
}, | ||
body: '{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}', | ||
}, | ||
response: { | ||
status: 204, | ||
}, | ||
handler: (req: MockRequest) => { | ||
req.expect.containsHeader("content-type", "application/jsonl"); | ||
req.expect.rawBodyEquals('{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}'); | ||
return { | ||
status: 204, | ||
}; | ||
}, | ||
kind: "MockApiDefinition", | ||
}); | ||
|
||
Scenarios.Stream_Jsonl_receive = passOnSuccess({ | ||
uri: "/stream/jsonl/receive", | ||
method: "get", | ||
request: {}, | ||
response: { | ||
status: 200, | ||
body: { | ||
rawContent: '{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}', | ||
contentType: "application/jsonl", | ||
}, | ||
}, | ||
kind: "MockApiDefinition", | ||
}); |