Skip to content

Commit

Permalink
Merge branch 'spector-jsonl' of github.com:microsoft/typespec into sp…
Browse files Browse the repository at this point in the history
…ector-jsonl
  • Loading branch information
tadelesh committed Mar 3, 2025
2 parents 29ddfba + 3439a05 commit 69349b3
Showing 2 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/http-specs/specs/stream/jsonl/main.tsp
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;
}
}
39 changes: 39 additions & 0 deletions packages/http-specs/specs/stream/jsonl/mockapi.ts
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",
});

0 comments on commit 69349b3

Please sign in to comment.