Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add spector test for jsonl #6201

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
@@ -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_AsBinary_receive

- Endpoint: `get /streaming/jsonl/as-binary/receive`

Jsonl streaming for response as binary.

### Streaming_Jsonl_AsBinary_send

- Endpoint: `post /streaming/jsonl/as-binary/send`

Jsonl streaming for request as binary.

### Type_Array_BooleanValue_get

- Endpoint: `get /type/array/boolean`
33 changes: 33 additions & 0 deletions packages/http-specs/specs/streaming/jsonl/main.tsp
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("as-binary")
namespace AsBinary {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I am a fan of AsBinary, its always binary. if you don't think NoStreaming and we can't find a better name Basic was ok

@scenario
@scenarioDoc("""
Jsonl streaming for request as binary.
""")
@route("send")
@post
op send(stream: JsonlStream<Info>): NoContentResponse;

@scenario
@scenarioDoc("""
Jsonl streaming for response as binary.
""")
@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_AsBinary_send = passOnSuccess({
uri: "/streaming/jsonl/as-binary/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_AsBinary_receive = passOnSuccess({
uri: "/streaming/jsonl/as-binary/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
@@ -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,
}),
Loading
Oops, something went wrong.