File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
packages/http-specs/specs/stream/jsonl Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments