Honor @encode(string) on C# boolean model properties - #11882
Open
JoshLove-msft with Copilot wants to merge 2 commits into
Open
Honor @encode(string) on C# boolean model properties#11882JoshLove-msft with Copilot wants to merge 2 commits into
JoshLove-msft with Copilot wants to merge 2 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix C# emitter to handle @encode(string) for boolean properties
Honor @encode(string) on C# boolean model properties
Sep 8, 2026
JoshLove-msft
marked this pull request as ready for review
September 8, 2026 22:55
JoshLove-msft
requested review from
Jorge Rangel (jorgerangel-msft),
Jose Arriaga Maldonado (joseharriaga),
Jesse Squire (jsquire) and
m-nash
as code owners
September 8, 2026 22:55
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is scoped to a new serialization format + MRW JSON read/write handling and is covered by both unit baselines and Spector integration tests for the targeted scenarios.
Pull request overview
Fixes the C# HTTP client emitter’s handling of @encode(string) on boolean model properties so JSON serialization uses string booleans (and deserialization accepts mixed-case string values), allowing the http/encode/boolean Spector scenarios to pass.
Changes:
- Adds a new
SerializationFormat.Boolean_Stringand mapsboolean+encode: "string"to it inTypeFactory. - Updates MRW JSON serialization/deserialization to write
"true"/"false"strings and parse string booleans viabool.Parse(...)whenBoolean_Stringis selected. - Adds unit baselines + unit tests for the new boolean-string serialization/deserialization statements, and adds typed Spector coverage for the four encode/boolean scenarios.
File summaries
| File | Description |
|---|---|
| packages/http-client-csharp/generator/TestProjects/Spector.Tests/TestProjects.Spector.Tests.csproj | Adds the Encode.Boolean generated test project reference so the Spector test assembly compiles/tests it. |
| packages/http-client-csharp/generator/TestProjects/Spector.Tests/Http/Encode/Boolean/EncodeBooleanTests.cs | Adds Spector integration tests for the four http/encode/boolean property scenarios plus negative decoding assertions. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/TypeFactory.cs | Maps InputPrimitiveTypeKind.Boolean with encode == "string" to the new SerializationFormat.Boolean_String. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/SerializationFormat.cs | Introduces the new Boolean_String serialization format. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/TestBooleanSerialization(string).cs | Baseline for boolean-as-string JSON write statement. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/TestBooleanSerialization(default).cs | Baseline for default boolean JSON write statement. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/TestBooleanDeserialization(string).cs | Baseline for boolean-as-string JSON read expression. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/TestBooleanDeserialization(default).cs | Baseline for default boolean JSON read expression. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs | Adds unit tests verifying the generated serialization/deserialization output for boolean (string vs default). |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs | Implements boolean string write/read behavior gated by SerializationFormat.Boolean_String. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
commit: |
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.
The C# emitter ignores
@encode(string)on boolean model properties, writing JSON booleans instead of strings and failing the fourhttp/encode/booleanSpector scenarios."true"/"false"strings."TRUE"and"FaLsE", while rejecting malformed values. Unencoded booleans retain existing behavior.new BoolAsStringProperty(true)serializes as{"value":"true"}rather than{"value":true}.