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 1 commit
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
Next Next commit
add spector test for jsonl
  • Loading branch information
tadelesh committed Mar 3, 2025
commit aad48981ed7fb769659c9181b1adb78805b2f457
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_Basic_receive

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

Basic case of jsonl streaming for response.

### Streaming_Jsonl_Basic_send

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

Basic case of jsonl streaming for request.

### 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("basic")
namespace Basic {
Copy link
Member

Choose a reason for hiding this comment

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

only potential suggestion would name this NoStreaming or something like that so it reflect that this is a case where you get the log ine one go at the end

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed.

@scenario
@scenarioDoc("""
Basic case of jsonl streaming for request.
""")
@route("send")
@post
op send(stream: JsonlStream<Info>): NoContentResponse;

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

model Info {
desc: string;
}
}
39 changes: 39 additions & 0 deletions packages/http-specs/specs/streaming/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.Streaming_Jsonl_Basic_send = passOnSuccess({
uri: "/streaming/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.Streaming_Jsonl_Basic_receive = passOnSuccess({
uri: "/streaming/jsonl/receive",
method: "get",
request: {},
response: {
status: 200,
body: {
rawContent: '{"desc": "one"}\n{"desc": "two"}\n{"desc": "three"}',
contentType: "application/jsonl",
},
},
kind: "MockApiDefinition",
});
Loading
Oops, something went wrong.