Skip to content

[CSharp] Add ExampleMockValueBuilder for test/sample generation (M1)#10376

Open
radhgupta wants to merge 1 commit intomicrosoft:mainfrom
radhgupta:feature/test-sample-generation
Open

[CSharp] Add ExampleMockValueBuilder for test/sample generation (M1)#10376
radhgupta wants to merge 1 commit intomicrosoft:mainfrom
radhgupta:feature/test-sample-generation

Conversation

@radhgupta
Copy link
Copy Markdown
Member

@radhgupta radhgupta commented Apr 14, 2026

This pull request introduces a new utility class, ExampleMockValueBuilder, to the codebase. This class provides functionality for generating mock InputOperationExample instances for operations that lack explicit examples in the specification. The builder covers a wide range of parameter and type scenarios, ensuring comprehensive and realistic mock data for testing or documentation purposes.

New mock example generation utilities:

  • Added ExampleMockValueBuilder class in Microsoft.TypeSpec.Generator.Samples namespace, which generates mock examples for operations without provided examples, supporting both "ShortVersion" (required parameters only) and "AllParameters" (all parameters) variants.
  • Implemented detailed logic to generate example values for all supported input types, including primitives, arrays, dictionaries, enums, models (with cycle detection), unions, literals, and special encodings (e.g., UUID, date/time, durations).
  • Handles constant, default, and endpoint parameters with appropriate mock values, and supports model inheritance and discriminators for complex types.

Design doc

https://gist.github.com/radhgupta/9fee69190f1ac2252a88dd88f99de327

This is M1 of the test/sample generation milestones. Next: M2 (Expression Converter).

Co-authored-by: Copilot <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 Apr 14, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 14, 2026

Open in StackBlitz

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

commit: 44175f4

@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