Skip to content

[http-client-csharp] Emit LRO status metadata - #12628

Open
iscai-msft wants to merge 1 commit into
microsoft:mainfrom
iscai-msft:dotnet-shared-lro-status-metadata
Open

iscai-msft wants to merge 1 commit into
microsoft:mainfrom
iscai-msft:dotnet-shared-lro-status-metadata

Conversation

@iscai-msft

Copy link
Copy Markdown
Member

Splits the status-metadata part out of #12563. That PR keeps @lroOperationId only.

What

When an LRO method has @lroStatusMetadata selections (TCGC lroMetadata.statusMetadata), the emitter adds two fields to lroMetadata:

  • pollingResponseModel: a $ref to the status-monitor response model, converted through the normal fromSdkType path.
  • statusMetadata[]: { property, propertySegments }. Each entry is a $ref to the polling model's own cached InputModelProperty (or a base model's property), not a copy.

The polling model graph (including nested models and enums) gets Output | Json usage. It is therefore always generated with its JSON deserializer, even when the status monitor operation is hidden (for example @scope("!csharp")). Consumers read metadata by deserializing the latest polling response once with the generated Deserialize{Model}, then returning that model's properties.

On the C# side, InputLongRunningServiceMetadata gains PollingResponseModel and StatusMetadata (IReadOnlyList<InputLroStatusMetadata>), along with a new ctor overload; the existing 3-arg ctor is unchanged. InputLongRunningServiceMetadataConverter now skips unknown properties instead of looping forever.

No generated output changes for the unbranded generator. The new public type, properties, and ctor are Input contract API for downstream generators, and the Azure generator owns the operation subclass that consumes them.

Review feedback from #12563

  • No emitter-side C# naming or rename logic and no custom metadata enums. Names come from the normal model and enum naming path, and customization stays with the generator ([CodeGenType]).
  • No ModelReaderWriterContextDefinition change, because there is no new metadata wrapper type.
  • No new PropertyProvider overload.
  • No main.tsp in TestData; the fixture JSON is generated from emitter output, and an emitter test asserts it stays in sync.

Known limitation

If the polling response model uses @alternateType, the original model is still converted when status metadata is present.

Tests

  • Emitter: 448 passed. New LRO status metadata tests cover property references and ordering, usage on a hidden monitor, no fields when nothing is selected, and fixture sync.
  • Microsoft.TypeSpec.Generator.Input.Tests: 337 passed, including new deserialization and unknown-property tests.
  • Microsoft.TypeSpec.Generator.ClientModel.Tests: 2820 passed.

Emit @lroStatusMetadata selections as references to the polling response
model's own properties, and ensure the polling model graph is generated
with JSON deserialization so consumers can reuse its generated deserializer.
Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:10
@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 Nov 20, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@12628

commit: ecb9cac

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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.

🟡 Changes recommended

Hidden monitors can leave cached input-only base models missing Output | Json usage, and required-field validation failures lack negative test coverage.

2 open issues
What changed in this PR

Adds LRO status metadata to the C# emitter’s shared input contract for downstream generators, preserving references to polling models and their properties.

Changes:

  • Emits polling-response models and ordered status selections, promoting model graphs to JSON output usage.
  • Adds C# input types and deserialization support while preserving existing constructors and skipping unknown metadata fields.
  • Adds emitter and C# tests with a shared, synchronization-checked JSON fixture.
File Description
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​test/​TestData/​InputServiceMethodTests/​LoadsEmittedLroStatusMetadata/​tspCodeModel.json Shared emitted metadata fixture.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​test/​InputServiceMethodTests.cs Tests references, legacy input, and unknown fields.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​TypeSpecSerialization.cs Registers the status metadata converter.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputLroStatusMetadataConverter.cs Deserializes selections and required property paths.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputLongRunningServiceMetadataConverter.cs Reads new fields and skips unknown properties.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputLroStatusMetadata.cs Defines the C# status-selection contract.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputLongRunningServiceMetadata.cs Adds polling model and selection properties.
packages/​http-client-csharp/​emitter/​test/​Unit/​operation-converter.test.ts Tests selection identity, usage, omission, and fixture synchronization.
packages/​http-client-csharp/​emitter/​src/​type/​input-service-method.ts Defines TypeScript status metadata contracts.
packages/​http-client-csharp/​emitter/​src/​lib/​operation-converter.ts Converts selections and promotes polling graph usage.

Review effort: Balanced

Comment on lines +749 to +754
for (const type of outputTypes) {
const inputType = sdkContext.__typeCache.types.get(type);
if (inputType?.kind === "model" || inputType?.kind === "enum") {
inputType.usage |= UsageFlags.Output | UsageFlags.Json;
}
}
Comment on lines +31 to +33
return new InputLroStatusMetadata(
property ?? throw new JsonException("LRO status metadata must have a property."),
propertySegments ?? throw new JsonException("LRO status metadata must have property segments."));

This branch has not been deployed

No deployments
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.

2 participants