Skip to content

Commit 69349b3

Browse files
committed
Merge branch 'spector-jsonl' of github.com:microsoft/typespec into spector-jsonl
2 parents 29ddfba + 3439a05 commit 69349b3

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import "@typespec/http";
2+
import "@typespec/http/streams";
3+
import "@typespec/spector";
4+
5+
using Http;
6+
using Http.Streams;
7+
using Spector;
8+
9+
@doc("Test of jsonl stream.")
10+
@scenarioService("/stream/jsonl")
11+
namespace Stream.Jsonl;
12+
13+
@scenario
14+
@scenarioDoc("""
15+
Basic case of jsonl stream.
16+
""")
17+
@route("basic")
18+
namespace Basic {
19+
@route("send")
20+
@post
21+
op send(stream: JsonlStream<Info>): NoContentResponse;
22+
23+
@route("receive")
24+
op receive(): JsonlStream<Info>;
25+
26+
model Info {
27+
desc: string;
28+
}
29+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
2+
3+
export const Scenarios: Record<string, ScenarioMockApi> = {};
4+
5+
Scenarios.Stream_Jsonl_send = passOnSuccess({
6+
uri: "/stream/jsonl/send",
7+
method: "post",
8+
request: {
9+
headers: {
10+
"Content-Type": "application/jsonl",
11+
},
12+
body: '{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}',
13+
},
14+
response: {
15+
status: 204,
16+
},
17+
handler: (req: MockRequest) => {
18+
req.expect.containsHeader("content-type", "application/jsonl");
19+
req.expect.rawBodyEquals('{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}');
20+
return {
21+
status: 204,
22+
};
23+
},
24+
kind: "MockApiDefinition",
25+
});
26+
27+
Scenarios.Stream_Jsonl_receive = passOnSuccess({
28+
uri: "/stream/jsonl/receive",
29+
method: "get",
30+
request: {},
31+
response: {
32+
status: 200,
33+
body: {
34+
rawContent: '{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}',
35+
contentType: "application/jsonl",
36+
},
37+
},
38+
kind: "MockApiDefinition",
39+
});

0 commit comments

Comments
 (0)