Sample Generation - ExampleValueExpressionBuilder and OperationSample parity with autorest generator#10739
Draft
MaiLinhP wants to merge 15 commits into
Draft
Sample Generation - ExampleValueExpressionBuilder and OperationSample parity with autorest generator#10739MaiLinhP wants to merge 15 commits into
MaiLinhP wants to merge 15 commits into
Conversation
…y to be namespace aware
commit: |
Contributor
|
No changes needing a change description found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.