Skip to content

[.NET] Consume TCGC LRO operation ID metadata - #12563

Open
iscai-msft wants to merge 10 commits into
microsoft:mainfrom
iscai-msft:dotnet-shared-lro-metadata
Open

iscai-msft wants to merge 10 commits into
microsoft:mainfrom
iscai-msft:dotnet-shared-lro-metadata

Conversation

@iscai-msft

@iscai-msft iscai-msft commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Consumes TCGC 0.74.0 @lroOperationId metadata in the shared .NET emitter/input model, so the Azure generator can expose the server-issued operation ID through an internal Operation subclass that overrides Operation.Id.

@lroStatusMetadata support has been split out into a separate, independent PR. Its original combined snapshot is preserved at iscai-msft:preserve/dotnet-shared-lro-metadata-ffa8e1f9b (ffa8e1f9b33ada0147d7ee92d1f93c07e5e79a98).

Feature links:

Part of Azure/typespec-azure#5996

Changes

  • Emitter: serializes lroMetadata.operationId, preserving TCGC order:
    • path selections include the polling link source (ResponseHeader, ResponseBody or Self), the polling operation's own path parameter (the same $ref as the polling method parameter) and pollingPath.
    • property selections include property and the typed propertySegments.
    • When the polling model is not emitted, the JSON wire name is resolved from @encodedName.
    • Invalid selections report general-error and are dropped without discarding valid ones.
  • Input model:
    • InputLongRunningServiceMetadata.OperationId (IReadOnlyList<InputLroOperationIdMetadata>), with derived types InputLroOperationIdPathMetadata (Source, PathParameter, PollingPath) and InputLroOperationIdPropertyMetadata (Property, PropertySegments).
    • New types InputOperationLink / InputOperationLinkLocation.
    • New InputPathParameter.Style / InputPathParameterStyle. Unknown values map to Unknown.
    • The LRO metadata converter now skips unknown properties.
  • No generated output changes. Generated methods still return Operation<T> / Operation<BinaryData>, and specs without these decorators are unaffected. No new public generated type, property or method comes from these decorators.

Validation

  • Emitter: 471 passed. Includes the fixture-sync test for LoadsEmittedLroMetadata/tspCodeModel.json and covers path, property, both and none; declaration order; cross-client polling; unexposed polling methods and models; link locations; path styles; and malformed input.
  • C#: Input 360, Generator 3244 and ClientModel 2820 tests pass. Prettier, oxlint and dotnet format whitespace are clean.
  • The Azure-side Operation.Id generation and Spector validation belong to the Azure companion PR ([.NET] Consume TCGC LRO operation ID Azure/azure-sdk-for-net#64913).

No Chronus entry is included because @typespec/http-client-csharp isn't registered in .chronus/config.yaml.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@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 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: f7ea9e3

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@iscai-msft

Copy link
Copy Markdown
Member Author

/azp run typespec - ci

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

🔵 Needs a closer look

Matching shared-package versions and lifecycle validation in Azure/azure-sdk-for-net#64913 require maintainer confirmation beyond what this review can establish.

No open issues 🎉

What changed in this PR

Adds shared support for transporting TCGC long-running operation status metadata and operation-ID selections from the C# emitter into strongly typed generator inputs. This enables the coordinated Azure generator work without adding poller APIs or changing runtime polling behavior.

Changes:

  • Preserve ordered selections, typed property paths, shared references, and modeled polling routes.
  • Add C# input types and JSON converters while retaining legacy constructor compatibility and skipping unknown metadata fields.
  • Add emitter/deserialization regressions and document the custom-generator consumption contract.
File Description
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​test/​InputServiceMethodTests.cs Tests typed paths, reference identity, ordered IDs, invalid inputs, and legacy compatibility.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​TypeSpecSerialization.cs Registers the new metadata converters.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputOperationLinkConverter.cs Deserializes and validates polling-link sources.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputLroStatusMetadataConverter.cs Deserializes selected status properties and typed paths.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputLroOperationIdMetadataConverter.cs Deserializes path-based and property-based ID selections.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​Serialization/​InputLongRunningServiceMetadataConverter.cs Loads both collections and skips unknown fields.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputOperationLink.cs Represents a polling link’s location and property.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputLroStatusMetadata.cs Represents a selected status property and access path.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputLroOperationIdPropertyMetadata.cs Represents a monitor-body ID selection.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputLroOperationIdPathMetadata.cs Carries the polling link, ID parameter, and monitor route.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputLroOperationIdMetadata.cs Adds the shared base type for ID selections.
packages/​http-client-csharp/​generator/​Microsoft.TypeSpec.Generator.Input/​src/​InputTypes/​InputLongRunningServiceMetadata.cs Exposes metadata collections while preserving existing constructors.
packages/​http-client-csharp/​emitter/​test/​Unit/​operation-converter.test.ts Tests selection combinations, names, ordering, types, and serialized references.
packages/​http-client-csharp/​emitter/​src/​type/​input-service-method.ts Defines the TypeScript metadata transport shapes.
packages/​http-client-csharp/​emitter/​src/​lib/​type-converter.ts Exports model-property conversion for reuse.
packages/​http-client-csharp/​emitter/​src/​lib/​operation-converter.ts Converts TCGC selections and preserves polling-route and header details.
packages/​http-client-csharp/​docs/​plugins.md Documents metadata semantics, consumer responsibilities, and matching-build requirements.

Review effort: Balanced

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.

thanks for driving this! Do we have a gist or proposal for what the generated output will look like, or is that all covered in Azure/azure-sdk-for-net#64913 ?

@iscai-msft
iscai-msft disabled auto-merge November 18, 2026 16:03
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 17:06
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

Scoped-out monitors can convert unrelated properties and disrupt generation, while explicit @body polling URLs are emitted with the wrong source location.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 18, 2026 17:20

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

Monitor conversion can diagnose or emit unrelated models, and whole-body polling URLs lose their distinction from JSON property selections.

4 open issues

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 20:04

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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 21:22

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

Metadata enum names can still collide with generated models after C# name normalization and with client types, producing conflicting declarations.

2 open issues
3 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 22:10

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.

🔵 Needs a closer look

Potential generated-type name collisions and nested CLR type visibility issues warrant human assessment across several code-generation paths.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Remove the public PropertyProvider isOutputOnly overload, use Enum.TryParse
for operation link locations and path styles, separate LRO metadata enum
usage from naming, clarify context registration, and inline the fixture
TypeSpec source in the emitter test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:57

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

With keepAll, a public polling monitor property can expose an internal model type, causing generated C# to fail compilation with CS0053.

1 open issue

Review effort: Balanced

usedTypeNames.add(name);
if (!model.isExactName) {
// ModelProvider may project Request/Response suffixes to Content/Result.
if (name.endsWith("REQUEST")) usedTypeNames.add(`${name.slice(0, -7)}CONTENT`);

@jorgerangel-msft Jorge Rangel (jorgerangel-msft) Nov 19, 2026 •

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.

I'm wondering if we should just let the generator handle the rename here. A custom visitor can override our rename rules without using the isExactName function.

foreach (var provider in buildableProviders)
{
if (!IsPublicApi(provider)
if (!(IsPublicApi(provider) || IsInternalLroMetadataType(provider, lroMetadataTypes))

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 validate if we actually need to do this? If I recall, these attributes should only ever be added for providers or types that implement IPersistableModel. From your other PR, I don't think the metadata type falls into that category so technically it should ever be part of buildableProviders ?


// LRO metadata enums are synthesized by this emitter from TCGC constants, so TCGC does not reserve their names.
// They must have distinct C# type and output file names without renaming existing types.
const usedTypeNames = new Set([...clients].map(csharpTypeNameKey));

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.

This reserves the original client names, but TypeSpecSerialization.BuildClientName (TypeSpecSerialization.cs:124-140) renames a deeper Root -> Group -> Child client to GroupChild; a hidden Group monitor selecting child?: "ready" can therefore emit a metadata enum with the same fully qualified name when both use a shared @clientNamespace. Could we resolve this using the final C# client names, ideally in the generator, and add a deeper-subclient regression?

🤖 Generated by Jorge's Copilot

Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:28
@iscai-msft
iscai-msft force-pushed the dotnet-shared-lro-metadata branch from fc068e9 to 718e6a0 Compare November 20, 2026 18:28
@iscai-msft iscai-msft changed the title [.NET] Consume TCGC LRO status metadata and operation ID [.NET] Consume TCGC LRO operation ID metadata Nov 20, 2026
Restore the original PR history and keep only TCGC @lroOperationId support.
@lroStatusMetadata support moves to a separate PR.
@iscai-msft
iscai-msft force-pushed the dotnet-shared-lro-metadata branch from 718e6a0 to f7ea9e3 Compare November 20, 2026 18:35

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.

fromSdkModelProperty(sdkContext, sdkProperty, metadata.pollingInfo.responseModel),
);
// TCGC omits serialization options when the polling model is not otherwise emitted.
if (property && property.serializedName === undefined && sdkProperty.__raw) {
const sdkPathParameters = sdkPollingOperation.parameters.filter(
(parameter) =>
parameter.kind === "path" &&
parameter.crossLanguageDefinitionId === entry.pathParameter.crossLanguageDefinitionId,
Comment on lines +843 to +845
const pathParameter = diagnostics.pipe(
fromParameter(sdkContext, sdkPathParameters[0], rootApiVersions),
);
Comment on lines +888 to +891
const sourceProperty =
location === InputOperationLinkLocation.ResponseHeader
? { ...convertedSource, serializedName: getHeaderFieldName(sdkContext.program, rawSource) }
: convertedSource;
kind: "path",
source: { location, property: sourceProperty },
pathParameter,
pollingPath: pollingOperation.path,
Comment on lines +33 to +36
/// <summary>
/// The URI template expansion style, or <see cref="InputPathParameterStyle.Unknown"/> when unavailable.
/// </summary>
public InputPathParameterStyle Style { get; internal set; }
Comment on lines 159 to +160
lroPagingMethod.lroMetadata = diagnostics.pipe(
loadLongRunningMetadata(sdkContext, sdkMethod),
loadLongRunningMetadata(sdkContext, sdkMethod, rootApiVersions),
Copilot AI balanced review requested due to automatic review settings November 20, 2026 18:43

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.

Comment on lines +120 to +122
parameter.Style = Enum.TryParse<InputPathParameterStyle>(style, ignoreCase: true, out var parsedStyle) && Enum.IsDefined(parsedStyle)
? parsedStyle
: InputPathParameterStyle.Unknown;

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.

3 participants