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
7 changes: 7 additions & 0 deletions .chronus/changes/spector-jsonl-2025-2-3-11-41-47.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

Add tests for basic jsonl streaming.
7 changes: 7 additions & 0 deletions .chronus/changes/spector-jsonl-2025-2-3-22-44-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/spector"
---

Support `application/jsonl` as binary.
12 changes: 12 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -3537,6 +3537,18 @@ Verify that the name "with" works. Send this parameter to pass with value `ok`.

Verify that the name "yield" works. Send this parameter to pass with value `ok`.

### Streaming_Jsonl_Basic_receive

- Endpoint: `get /streaming/jsonl/basic/receive`

Basic jsonl streaming for response.

### Streaming_Jsonl_Basic_send

- Endpoint: `post /streaming/jsonl/basic/send`

Basic jsonl streaming for request.

### Type_Array_BooleanValue_get

- Endpoint: `get /type/array/boolean`
Expand Down
33 changes: 33 additions & 0 deletions packages/http-specs/specs/streaming/jsonl/main.tsp
Comment thread
tadelesh marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import "@typespec/http";
import "@typespec/http/streams";
import "@typespec/spector";

using TypeSpec.Http;
using TypeSpec.Http.Streams;
using Spector;

@doc("Test of jsonl streaming.")
@scenarioService("/streaming/jsonl")
namespace Streaming.Jsonl;

@route("basic")
namespace Basic {
Comment thread
tadelesh marked this conversation as resolved.
Resolved
@scenario
@scenarioDoc("""
Basic jsonl streaming for request.
""")
@route("send")
@post
op send(stream: JsonlStream<Info>): NoContentResponse;

@scenario
@scenarioDoc("""
Basic jsonl streaming for response.
""")
@route("receive")
op receive(): JsonlStream<Info>;

model Info {
desc: string;
}
}
32 changes: 32 additions & 0 deletions packages/http-specs/specs/streaming/jsonl/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Scenarios.Streaming_Jsonl_Basic_send = passOnSuccess({
uri: "/streaming/jsonl/basic/send",
method: "post",
request: {
headers: {
"Content-Type": "application/jsonl",
},
body: Buffer.from('{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}'),
},
response: {
status: 204,
},
kind: "MockApiDefinition",
});

Scenarios.Streaming_Jsonl_Basic_receive = passOnSuccess({
uri: "/streaming/jsonl/basic/receive",
method: "get",
request: {},
response: {
status: 200,
body: {
rawContent: Buffer.from('{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}'),
contentType: "application/jsonl",
},
},
kind: "MockApiDefinition",
});
2 changes: 1 addition & 1 deletion packages/spector/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class MockApiServer {
this.app.use(bodyParser.text({ type: "text/plain" }));
this.app.use(
bodyParser.raw({
type: ["application/octet-stream", "image/png"],
type: ["application/octet-stream", "image/png", "application/jsonl"],
limit: "10mb",
verify: rawBinaryBodySaver,
}),
Expand Down