-
Notifications
You must be signed in to change notification settings - Fork 366
[http-client-csharp] Adopt streaming/jsonl Spector scenario and fix BinaryContent wrapping #10740
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
Open
JonathanCrd
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
JonathanCrd:joncarde/spector-streaming-jsonl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
6ed8048
fix: [http-client-csharp] wrap BinaryData with BinaryContent.Create i…
JonathanCrd e5cca81
chore: [http-client-csharp] regenerate Sample-TypeSpec after BinaryCo…
JonathanCrd 952f63e
test: [http-client-csharp] adopt streaming/jsonl Spector scenario
JonathanCrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ttp-client-csharp/generator/TestProjects/Spector.Tests/Http/Streaming/Jsonl/JsonlTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using NUnit.Framework; | ||
| using Streaming.Jsonl; | ||
|
|
||
| namespace TestProjects.Spector.Tests.Http.Streaming.Jsonl | ||
| { | ||
| public class JsonlTests : SpectorTestBase | ||
| { | ||
| private const string ExpectedJsonl = "{\"desc\": \"one\"}\n{\"desc\": \"two\"}\n{\"desc\": \"three\"}"; | ||
|
|
||
| [SpectorTest] | ||
| public Task BasicSend() => Test(async (host) => | ||
| { | ||
| var client = new JsonlClient(host, null).GetBasicClient(); | ||
| var stream = StreamingJsonlModelFactory.JsonlStreamInfo(BinaryData.FromString(ExpectedJsonl)); | ||
| var response = await client.SendAsync(stream); | ||
|
|
||
| Assert.AreEqual(204, response.GetRawResponse().Status); | ||
| }); | ||
|
|
||
| [SpectorTest] | ||
| public Task BasicReceive() => Test(async (host) => | ||
| { | ||
| var client = new JsonlClient(host, null).GetBasicClient(); | ||
| var response = await client.ReceiveAsync(); | ||
|
|
||
| Assert.AreEqual(200, response.GetRawResponse().Status); | ||
| BinaryDataAssert.AreEqual(BinaryData.FromString(ExpectedJsonl), response.Value); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/Configuration.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "package-name": "Streaming.Jsonl" | ||
| } |
6 changes: 6 additions & 0 deletions
6
...-csharp/generator/TestProjects/Spector/http/streaming/jsonl/Streaming.Jsonl.NuGet.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <Project> | ||
| <ItemGroup> | ||
| <JsonSchemaSegment Include="$(MSBuildThisFileDirectory)..\..\ConfigurationSchema.json" | ||
| FilePathPattern="appsettings.*.json" /> | ||
| </ItemGroup> | ||
| </Project> |
3 changes: 3 additions & 0 deletions
3
...tp-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/Streaming.Jsonl.slnx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <Solution> | ||
| <Project Path="src/Streaming.Jsonl.csproj" /> | ||
| </Solution> |
38 changes: 38 additions & 0 deletions
38
...-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/Basic.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using TypeSpec.Http.Streams; | ||
|
|
||
| namespace Streaming.Jsonl._Basic | ||
| { | ||
| public partial class Basic | ||
| { | ||
| protected Basic() => throw null; | ||
|
|
||
| internal Basic(ClientPipeline pipeline, Uri endpoint) => throw null; | ||
|
|
||
| public ClientPipeline Pipeline => throw null; | ||
|
|
||
| public virtual ClientResult Send(BinaryContent content, RequestOptions options = null) => throw null; | ||
|
|
||
| public virtual Task<ClientResult> SendAsync(BinaryContent content, RequestOptions options = null) => throw null; | ||
|
|
||
| public virtual ClientResult Send(JsonlStreamInfo stream, CancellationToken cancellationToken = default) => throw null; | ||
|
|
||
| public virtual Task<ClientResult> SendAsync(JsonlStreamInfo stream, CancellationToken cancellationToken = default) => throw null; | ||
|
|
||
| public virtual ClientResult Receive(RequestOptions options) => throw null; | ||
|
|
||
| public virtual Task<ClientResult> ReceiveAsync(RequestOptions options) => throw null; | ||
|
|
||
| public virtual ClientResult<BinaryData> Receive(CancellationToken cancellationToken = default) => throw null; | ||
|
|
||
| public virtual Task<ClientResult<BinaryData>> ReceiveAsync(CancellationToken cancellationToken = default) => throw null; | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
...t-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/JsonlClient.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel.Primitives; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Streaming.Jsonl._Basic; | ||
|
|
||
| namespace Streaming.Jsonl | ||
| { | ||
| public partial class JsonlClient | ||
| { | ||
| public JsonlClient() : this(new Uri("http://localhost:3000"), new JsonlClientOptions()) => throw null; | ||
|
|
||
| internal JsonlClient(AuthenticationPolicy authenticationPolicy, Uri endpoint, JsonlClientOptions options) => throw null; | ||
|
|
||
| public JsonlClient(Uri endpoint, JsonlClientOptions options) : this(null, endpoint, options) => throw null; | ||
|
|
||
| [Experimental("SCME0002")] | ||
| public JsonlClient(JsonlClientSettings settings) : this(AuthenticationPolicy.Create(settings), settings?.Endpoint, settings?.Options) => throw null; | ||
|
|
||
| public ClientPipeline Pipeline => throw null; | ||
|
|
||
| public virtual Basic GetBasicClient() => throw null; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...p/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/JsonlClientOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System.ClientModel.Primitives; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| namespace Streaming.Jsonl | ||
| { | ||
| public partial class JsonlClientOptions : ClientPipelineOptions | ||
| { | ||
| public JsonlClientOptions() => throw null; | ||
|
|
||
| [Experimental("SCME0002")] | ||
| internal JsonlClientOptions(IConfigurationSection section) : base(section) => throw null; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
.../generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/JsonlClientSettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel.Primitives; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| namespace Streaming.Jsonl | ||
| { | ||
| [Experimental("SCME0002")] | ||
| public partial class JsonlClientSettings : ClientSettings | ||
| { | ||
| public Uri Endpoint | ||
| { | ||
| get => throw null; | ||
| set => throw null; | ||
| } | ||
|
|
||
| public JsonlClientOptions Options | ||
| { | ||
| get => throw null; | ||
| set => throw null; | ||
| } | ||
|
|
||
| protected override void BindCore(IConfigurationSection section) => throw null; | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
...ojects/Spector/http/streaming/jsonl/src/Generated/Models/JsonlStreamInfo.Serialization.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel.Primitives; | ||
| using System.Text.Json; | ||
|
|
||
| namespace TypeSpec.Http.Streams | ||
| { | ||
| public partial class JsonlStreamInfo : IJsonModel<JsonlStreamInfo> | ||
| { | ||
| internal JsonlStreamInfo() => throw null; | ||
|
|
||
| protected virtual JsonlStreamInfo PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| BinaryData IPersistableModel<JsonlStreamInfo>.Write(ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| JsonlStreamInfo IPersistableModel<JsonlStreamInfo>.Create(BinaryData data, ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| string IPersistableModel<JsonlStreamInfo>.GetFormatFromOptions(ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| void IJsonModel<JsonlStreamInfo>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| JsonlStreamInfo IJsonModel<JsonlStreamInfo>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null; | ||
|
|
||
| protected virtual JsonlStreamInfo JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...nerator/TestProjects/Spector/http/streaming/jsonl/src/Generated/Models/JsonlStreamInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
|
|
||
| namespace TypeSpec.Http.Streams | ||
| { | ||
| public partial class JsonlStreamInfo | ||
| { | ||
| public BinaryData Body => throw null; | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
...r/TestProjects/Spector/http/streaming/jsonl/src/Generated/Models/StreamingJsonlContext.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System.ClientModel.Primitives; | ||
| using Streaming.Jsonl._Basic; | ||
| using TypeSpec.Http.Streams; | ||
|
|
||
| namespace Streaming.Jsonl | ||
| { | ||
| [ModelReaderWriterBuildable(typeof(JsonlStreamInfo))] | ||
| public partial class StreamingJsonlContext : ModelReaderWriterContext | ||
| { | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...tor/TestProjects/Spector/http/streaming/jsonl/src/Generated/StreamingJsonlModelFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using Streaming.Jsonl._Basic; | ||
| using TypeSpec.Http.Streams; | ||
|
|
||
| namespace Streaming.Jsonl | ||
| { | ||
| public static partial class StreamingJsonlModelFactory | ||
| { | ||
|
|
||
| public static JsonlStreamInfo JsonlStreamInfo(BinaryData body = default) => throw null; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically what you have is not incorrect. I did a quick glance at what jsonl and what it's use cases and it seems that one of the biggest uses is the ability to stream a file and serialize + deserialize each line as a JSON object. Consider the scenario where we have a very large file, where each line is a different json object. If we use
BinaryData, we would need to store the entire file content into memory. I think we would need to design a solution where we can stream the payload line by line, that way not the entire file contents is stored into memory.