Skip to content

[http-client-csharp] Add JSONL and SSE streaming support - #11462

Draft
JoshLove-msft wants to merge 4 commits into
microsoft:mainfrom
JoshLove-msft:josh/streaming-client-results
Draft

[http-client-csharp] Add JSONL and SSE streaming support#11462
JoshLove-msft wants to merge 4 commits into
microsoft:mainfrom
JoshLove-msft:josh/streaming-client-results

Conversation

@JoshLove-msft

Copy link
Copy Markdown
Contributor

Summary

  • preserve JSONL and SSE stream metadata in the C# emitter code model
  • generate incremental IAsyncEnumerable<T> JSONL requests and AsyncStreamingClientResult<T> JSONL responses
  • generate unbuffered SSE responses as AsyncStreamingClientResult<SseItem<BinaryData>>, including terminal-event suppression
  • add live Spector coverage for JSONL send/receive and all unnamed, named, and retrieval SSE scenarios
  • consume the streaming result APIs introduced by Add streaming client result abstractions Azure/azure-sdk-for-net#60994

Closes #10738

Validation

  • npm run build
  • npm test
  • npm run cop
  • Test-Spector.ps1 -filter "http/streaming/jsonl"
  • Test-Spector.ps1 -filter "http/streaming/sse"

npm run lint -- --emitter is currently blocked by the package resolving ESLint 10 while retaining a legacy ESLint configuration (eslint.config.* is not present).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e02ee7d0-8d27-46f8-a856-222d6a938ecd
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jul 29, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e02ee7d0-8d27-46f8-a856-222d6a938ecd
@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e02ee7d0-8d27-46f8-a856-222d6a938ecd
@JoshLove-msft
JoshLove-msft marked this pull request as draft July 29, 2026 23:42
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e02ee7d0-8d27-46f8-a856-222d6a938ecd

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds end-to-end JSONL and SSE streaming support to the http-client-csharp pipeline by carrying streaming metadata through the emitter input model and consuming the newer System.ClientModel streaming APIs in the C# generator, with Spector scenarios + tests added for coverage.

Changes:

  • Extend the emitter input model to represent streaming payloads (kind: "streaming") and preserve JSONL/SSE metadata (stream kind, content types, SSE terminal event).
  • Update the C# generator to translate streaming types into IAsyncEnumerable<T> request parameters and AsyncStreamingClientResult<T> / AsyncStreamingClientResult<SseItem<T>> responses, and add a JSONL request content helper.
  • Add Spector projects + NUnit tests for JSONL send/receive and SSE unnamed/named/retrieval scenarios; bump dependencies to consume the new streaming APIs.

Reviewed changes

Copilot reviewed 111 out of 134 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/http-client-csharp/package.json Adds @typespec/events dependency; bumps @typespec/http-specs and @typespec/spector to pick up streaming/SSE specs & tooling.
packages/http-client-csharp/generator/Packages.Data.props Bumps System.ClientModel and related deps to versions that expose streaming result APIs.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/common/InputFactory.cs Allows tests to specify bufferResponse on operations (needed for unbuffered streaming responses).
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Utilities/ExternalTypeReferenceResolver.cs Traverses InputStreamingType so external type metadata collection doesn’t miss streaming item types.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/TypeFactory.cs Maps InputStreamingType to IAsyncEnumerable<T> for request-side convenience method shaping.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Properties/launchSettings.json Adds debug launch profiles for the new Spector streaming scenarios.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Primitives/NewProjectScaffolding.cs Updates scaffolding to the newer System.ClientModel package version.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Primitives/CSharpType.cs Makes IsIAsyncEnumerableOfT public to support streaming-related codegen decisions.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/TypeSpecSerialization.cs Registers the new InputStreamingType JSON converter.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputTypeConverter.cs Adds "streaming" kind dispatch to build InputStreamingType during deserialization.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputStreamingTypeConverter.cs New: deserializes streaming type metadata (kind/contentTypes/streamKind/terminal event) from tsp code model JSON.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputStreamingType.cs New: input-model representation of streaming types.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ScmTypeFactory.cs Ensures root-output-model discovery walks through streaming item types.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ScmOutputLibrary.cs Emits JsonLinesBinaryContent helper into the generated output library.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ScmMethodProviderCollection.cs Core codegen changes: generates JSONL/SSE unbuffered streaming results; supports JSONL request convenience overloads using IAsyncEnumerable<T>; adds SSE terminal event suppression logic.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/JsonLinesBinaryContentDefinition.cs New: implements async-only JSONL request body writer and shared JSON deserializers for JSONL/SSE payload parsing.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/ScmMethodProviderCollectionTests.cs Adds unit tests validating JSONL request overloads and JSONL/SSE streaming response shaping (including terminal-event suppression).
packages/http-client-csharp/eng/scripts/Spector-Helper.psm1 Removes http/streaming/jsonl from known failing Spector specs list.
packages/http-client-csharp/emitter/test/Unit/utils/test-util.ts Extends unit test host to include streams/events/sse libraries; adds IsSseNeeded compile option and imports/using statements.
packages/http-client-csharp/emitter/test/Unit/operation-converter.test.ts Adds emitter unit tests to ensure stream metadata and SSE terminal event info are preserved into the code model.
packages/http-client-csharp/emitter/src/type/input-type.ts Adds InputStreamingType to the emitter’s input type union.
packages/http-client-csharp/emitter/src/lib/operation-converter.ts Converts SdkStreamMetadata into InputStreamingType; sets bufferResponse false for supported streaming responses; extracts SSE terminal event info via events metadata.
packages/http-client-csharp/generator/TestProjects/Spector.Tests/TestProjects.Spector.Tests.csproj References the new streaming Spector projects so they’re built/available during filtered runs.
packages/http-client-csharp/generator/TestProjects/Spector.Tests/Infrastructure/TestServerBase.cs Updates server host/port detection to support non-numeric address outputs from the Spector server.
packages/http-client-csharp/generator/TestProjects/Spector.Tests/Http/Streaming/Jsonl/JsonlTests.cs New live Spector tests for JSONL send/receive.
packages/http-client-csharp/generator/TestProjects/Spector.Tests/Http/Streaming/Sse/SseTests.cs New live Spector tests for SSE unnamed/named/retrieval scenarios.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/Configuration.json New Spector streaming/jsonl test project configuration.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/tspCodeModel.json New: captured tsp code model for the JSONL streaming scenario.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/Streaming.Jsonl.slnx New solution wrapper for the JSONL streaming test project.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/Streaming.Jsonl.NuGet.targets New NuGet targets file for the JSONL streaming test project packaging metadata.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Streaming.Jsonl.csproj New JSONL streaming test project (references System.ClientModel streaming-capable version).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/Basic.cs New generated surface for JSONL send/receive methods (shows IAsyncEnumerable<T> + streaming result shapes).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/JsonlClient.cs New generated client entrypoint for JSONL streaming scenario.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/JsonlClientOptions.cs New generated options for JSONL client.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/JsonlClientSettings.cs New generated settings/binding for JSONL client.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/StreamingJsonlModelFactory.cs New generated model factory for JSONL scenario models.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/Models/Info.cs New generated JSONL model type(s).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/Models/Info.Serialization.cs New generated JSON serialization hooks for JSONL model(s).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/Models/StreamingJsonlContext.cs New generated MRW context entries for JSONL models.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/jsonl/src/Generated/schema/ConfigurationSchema.json New configuration schema artifact for JSONL project packaging.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/Configuration.json New Spector streaming/sse test project configuration.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/tspCodeModel.json New: captured tsp code model for the SSE streaming scenario.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/Streaming.Sse.slnx New solution wrapper for the SSE streaming test project.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/Streaming.Sse.NuGet.targets New NuGet targets file for the SSE streaming test project packaging metadata.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Streaming.Sse.csproj New SSE streaming test project (references System.ClientModel streaming-capable version).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/SseClient.cs New generated client entrypoint for SSE scenario.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/SseClientOptions.cs New generated options for SSE client.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/SseClientSettings.cs New generated settings/binding for SSE client.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Named.cs New generated SSE named-operation-group client surface.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Unnamed.cs New generated SSE unnamed-operation-group client surface.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Retrieve.cs New generated SSE retrieval-operation-group client surface.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/StreamingSseModelFactory.cs New generated model factory for SSE models.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/Info.cs New generated SSE model type(s).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/Info.Serialization.cs New generated JSON serialization hooks for SSE model(s).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/RetrievalRequest.cs New generated SSE request model type(s).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/RetrievalRequest.Serialization.cs New generated JSON serialization hooks for SSE request model(s).
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/StreamingSseContext.cs New generated MRW context entries for SSE models.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/schema/ConfigurationSchema.json New configuration schema artifact for SSE project packaging.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v1/src/Versioning.TypeChangedFrom.V1.csproj Bumps System.ClientModel to streaming-capable version across Spector project references.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v2/src/Versioning.TypeChangedFrom.V2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/returnTypeChangedFrom/v1/src/Versioning.ReturnTypeChangedFrom.V1.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/returnTypeChangedFrom/v2/src/Versioning.ReturnTypeChangedFrom.V2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v1/src/Versioning.RenamedFrom.V1.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v2/src/Versioning.RenamedFrom.V2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v1/src/Versioning.Removed.V1.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2/src/Versioning.Removed.V2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2Preview/src/Versioning.Removed.V2Preview.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v1/src/Versioning.MadeOptional.V1.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v2/src/Versioning.MadeOptional.V2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v1/src/Versioning.Added.V1.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v2/src/Versioning.Added.V2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/array/src/Type.Array.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/dictionary/src/Type.Dictionary.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/enum/fixed/src/Type.Enum.Fixed.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/enum/extensible/src/Type.Enum.Extensible.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/empty/src/Type.Model.Empty.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/usage/src/Type.Model.Usage.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/visibility/src/Type.Model.Visibility.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/src/Type.Model.Inheritance.SingleDiscriminator.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/recursive/src/Type.Model.Inheritance.Recursive.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/not-discriminated/src/Type.Model.Inheritance.NotDiscriminated.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/src/Type.Model.Inheritance.NestedDiscriminator.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/src/Type.Model.Inheritance.EnumDiscriminator.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/src/Type.Property.AdditionalProperties.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/nullable/src/Type.Property.Nullable.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/optionality/src/Type.Property.Optional.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/value-types/src/Type.Property.ValueTypes.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/scalar/src/Type.Scalar.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/type/union/src/Type.Union.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/special-words/src/SpecialWords.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/special-headers/repeatability/src/SpecialHeaders.Repeatability.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/special-headers/conditional-request/src/SpecialHeaders.ConditionalRequest.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/service/multiple-services/src/Service.MultipleServices.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/server/endpoint/not-defined/src/Server.Endpoint.NotDefined.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/server/path/single/src/Server.Path.Single.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/server/path/multiple/src/Server.Path.Multiple.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/server/versions/not-versioned/src/Server.Versions.NotVersioned.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/server/versions/versioned/src/Server.Versions.Versioned.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/serialization/encoded-name/json/src/Serialization.EncodedName.Json.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/routes/src/Routes.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/status-code-range/src/Response.StatusCodeRange.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/resiliency/srv-driven/v1/src/Resiliency.SrvDriven.V1.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/resiliency/srv-driven/v2/src/Resiliency.SrvDriven.V2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/payload/xml/src/Payload.Xml.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/payload/pageable/src/Payload.Pageable.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/src/Payload.MultiPart.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/payload/media-type/src/Payload.MediaType.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/payload/json-merge-patch/src/Payload.JsonMergePatch.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/payload/head/src/Payload.Head.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/payload/content-negotiation/src/Payload.ContentNegotiation.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/basic/src/Parameters.Basic.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/body-optionality/src/Parameters.BodyOptionality.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/body-root/src/Parameters.BodyRoot.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/collection-format/src/Parameters.CollectionFormat.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/path/src/Parameters.Path.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/query/src/Parameters.Query.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/spread/src/Parameters.Spread.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/encode/array/src/Encode.Array.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/encode/bytes/src/Encode.Bytes.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/encode/datetime/src/Encode.Datetime.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/encode/duration/src/Encode.Duration.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/encode/numeric/src/Encode.Numeric.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/documentation/src/Documentation.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/client/structure/default/src/Client.Structure.Service.Default.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/client/structure/multi-client/src/Client.Structure.Service.Multi.Client.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/client/structure/renamed-operation/src/Client.Structure.Service.Renamed.Operation.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/client/structure/two-operation-group/src/Client.Structure.Service.TwoOperationGroup.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/client/structure/client-operation-group/src/Client.Structure.Service.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/authentication/api-key/src/Authentication.ApiKey.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/authentication/http/custom/src/Authentication.Http.Custom.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/authentication/oauth2/src/Authentication.OAuth2.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Spector/http/authentication/union/src/Authentication.Union.csproj Same dependency bump for System.ClientModel.
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/SampleTypeSpec.csproj Aligns local sample project with updated System.ClientModel version.

): [InputStreamingType, readonly Diagnostic[]] {
const diagnostics = createDiagnosticCollector();
const originalType = streamMetadata.originalType;
const streamKind = getStreamKind(streamMetadata)!;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is streamkind guaranteed to not be undefined here ?


protected override CSharpType[] GetTypeArguments() => [_t];

protected override string BuildName() => "JsonLinesBinaryContent";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: will this type be used for azure clients? If so, should we consider using the ScmCodeModelGenerator.Instance.TypeFactory.RequestContentApi.RequestContentType as the prefix ?

out var writer));
loop.Add(writer.As<Utf8JsonWriter>().WriteObjectValue(value.As(_t), wireOptions));
loop.Add(writer.As<Utf8JsonWriter>().FlushAsync(cancellationToken).Terminate());
loop.Add(Declare("bytes", typeof(byte[]), buffer.Invoke(nameof(MemoryStream.ToArray)), out var bytes));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: should we add a new api to MemoryStreamSnippets ?

signature,
new MethodBodyStatement[]
{
Return(data.Invoke("ToObjectFromJson", [], [_t]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: can we use the ToObjectFromJson snippet?

ScmCodeModelGenerator.Instance.TypeFactory.HttpMessageApi.HttpMessageType,
This.Invoke(_createRequestMethod.Signature, protocolArguments),
out var message),
message.Property("BufferResponse").Assign(False).Terminate(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: should we use the BufferResponse() api ?

var payloadCSharpType = payloadType is null
? typeof(BinaryData)
: ScmCodeModelGenerator.Instance.TypeFactory.CreateCSharpType(payloadType)
?? throw new InvalidOperationException("Unable to resolve SSE stream item type.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we log an error as well?

: terminalPredicate == Null
? [response]
: [response, terminalPredicate];
return Static(typeof(AsyncStreamingClientResult)).Invoke("CreateSse", rawArguments);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I'm wondering if we should consider creating some new snippets for AsyncStreamingClientResult ?

var helperType = new JsonLinesBinaryContentDefinition().Type.MakeGenericType(
[payloadCSharpType]);
var deserializeMethod = payloadType is InputModelType
? "DeserializeModel"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: since we are hardcoding this name in multiple places, should we consider storing it as a const so they are never out of sync?

return ScmCodeModelGenerator.Instance.TypeFactory.CreateCSharpType(responseType);
}

private InputStreamingType? GetStreamingResponse()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I noticed we called this method more than once. Should we consider caching it?


namespace Microsoft.TypeSpec.Generator.Input
{
internal sealed class InputStreamingTypeConverter : JsonConverter<InputStreamingType>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we please add unit tests to test deserializing this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-csharp] Add support for Streaming/JSONL scenarios

3 participants