Skip to content

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

Draft
MaiLinhP wants to merge 15 commits into
microsoft:mainfrom
MaiLinhP:sample
Draft

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

Conversation

@MaiLinhP
Copy link
Copy Markdown
Member

This PR implements Milestones 2 and 3 of the sample/test generation design for the TypeSpec C# generator, adding the core infrastructure to convert example values into C# expressions and to model operation samples with client chain resolution and parameter mapping.

Milestone 2 — Example Value → C# Expression Converter

ExampleValueExpressionBuilder — converts InputExampleValue + CSharpType into ValueExpression AST nodes. Handles all framework primitives (string, int, long, float, double, decimal, bool, Guid, Uri, byte[]), DateTimeOffset (format-aware: Parse vs FromUnixTimeSeconds), TimeSpan (format-aware: XmlConvert.ToTimeSpan vs FromSeconds), BinaryData, Stream, lists, dictionaries, models (with constructor parameter matching), and enums.
ExampleParameterValue — dual-mode bridge type: carries either a raw InputExampleValue (for spec-provided params) or a pre-built ValueExpression

Milestone 3 — Operation Sample Model

OperationSample — bridges InputOperationExample to everything needed for code generation: client invocation chain (walks subclient → root, collecting factory methods + constructor), parameter value mapping with known-parameter handling (endpoint, API key, token credential → DefaultAzureCredential, WaitUntil, RequestContent, MatchConditions, CancellationToken), inline vs out-of-line decision, and static helpers (ShouldGenerateSample, ShouldGenerateShortVersion).
ScmMethodProviderCollection.BuildSamples() — attaches protocol and convenience OperationSample instances to each method collection, respecting ShortVersion suppression logic.

@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: 2350208

@github-actions
Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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.

1 participant