Skip to content

C# emitter ignores @encode(string) on boolean model properties #11691

Description

@JoshLove-msft

Description

The C# HTTP client emitter cannot pass the http/encode/boolean Spector scenarios. A model property declared as @encode(string) value: boolean is generated as a C# bool, but its JSON serialization ignores the string encoding and writes a JSON boolean.

Reproduction

From packages/http-client-csharp on current main:

pwsh eng/scripts/Test-Spector.ps1 -filter "http/encode/boolean"

Exercise the generated typed methods with new BoolAsStringProperty(true/false) for these scenarios:

  • Property/trueLower
  • Property/falseLower
  • Property/trueUpper
  • Property/falseMixed

All four requests receive HTTP 400 from Spector.

Generated behavior

BoolAsStringProperty.Serialization.cs currently emits:

writer.WritePropertyName("value"u8);
writer.WriteBooleanValue(Value);

The scenarios require string values ("true", "false", "TRUE", and "FaLsE") in both the request and response bodies. Deserialization likewise needs to honor the boolean string encoding.

Expected behavior

The generated serialization and deserialization should respect @encode(string) for boolean model properties so the http/encode/boolean Spector scenarios pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions