Skip to content

Sample Generation - ExampleValueExpressionBuilder and OperationSample parity with autorest generator#10739

Open
MaiLinhP wants to merge 21 commits into
microsoft:mainfrom
MaiLinhP:sample
Open

Sample Generation - ExampleValueExpressionBuilder and OperationSample parity with autorest generator#10739
MaiLinhP wants to merge 21 commits into
microsoft:mainfrom
MaiLinhP:sample

Conversation

@MaiLinhP
Copy link
Copy Markdown
Member

@MaiLinhP MaiLinhP commented May 19, 2026

Implements M1-M4 milestones for sample generation for the C# emitter — from mock value synthesis to emitting compilable Samples_{Client}.cs files. Based on the design document.

New Components
ExampleMockValueBuilder (M1) — Generates InputOperationExample instances for operations without spec-provided examples. Produces ShortVersion (required only) and AllParameters (with optional parameters) variants. This was simplified compared to autorest versions - instead of giving concrete mock values that matches the expected format for time/duration/different number types etc., mock values were simplified to "<{parameter name/encoded type hints}>" for strings, and 0 for numbers. This is because we're expecting AI based sample generator to read from deterministic samples and come up with scenario based mock values, hence a hint would be more useful than hardcoded mock values.

ExampleValueExpressionBuilder (M2) — Converts InputExampleValue → C# ValueExpression AST nodes. Covers all primitives, collections, enums, models, credentials ApiKeyCredential, DefaultAzureCredential, BinaryContent anonymous objects, streams, etc.

ExampleParameterValue (M2) — Dual-mode bridge holding either raw InputExampleValue or a pre-built ValueExpression for known parameters (credentials, endpoints).

OperationSample (M3) — Resolves client construction chains (subclient → root), parameter value mappings (with spread support), inline/out-of-line decisions, and paging response type unwrapping.

ClientSampleProvider (M4) — TypeProvider that emits tests/Generated/Samples/Samples_{Client}.cs with sync+async [Test]/[Ignore] methods. Handles normal, pageable (foreach/await foreach), and LRO invocation patterns with JSON response parsing. Note: Per design doc, BuildSamples
should live in ScmMethodProviderCollection.cs which is the equivalent of autorest OperationMethodChainBuilder.cs. However, coupling sample building with method building was purely for convenience, so it has been moved out to ClientSampleProvider for more clarity.

Infrastructure Changes
ScmOutputLibrary — Registers ClientSampleProvider for all clients
ScmMethodProviderCollection — Exposed MethodProviders for sample provider access

@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 May 19, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

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

commit: bd0f2ae

@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@MaiLinhP MaiLinhP marked this pull request as ready for review May 21, 2026 17:29
Copy link
Copy Markdown
Contributor

@jorgerangel-msft jorgerangel-msft left a comment

Choose a reason for hiding this comment

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

Sorry if I missed this, but do you have a design doc of the proposed sample generation pipeline? I think that will help with understanding where these changes fit in the overall picture.

];
}

protected virtual IReadOnlyList<OperationSample> BuildSamples()
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 there a reason why this is protected virtual? Is it for testing? Also do you think the sample building should be decoupled from the client method construction we do here?

@JoshLove-msft
Copy link
Copy Markdown
Contributor

Can we link to the design?

@JoshLove-msft
Copy link
Copy Markdown
Contributor

Can we add some example data to our test TSP?

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