Skip to content

Add support for array encoding with @encode(ArrayEncoding.*) decorator#9430

Merged
radhgupta merged 27 commits intomicrosoft:mainfrom
radhgupta:csv-encoding
Jan 30, 2026
Merged

Add support for array encoding with @encode(ArrayEncoding.*) decorator#9430
radhgupta merged 27 commits intomicrosoft:mainfrom
radhgupta:csv-encoding

Conversation

@radhgupta
Copy link
Member

@radhgupta radhgupta commented Jan 21, 2026

This pull request adds support for custom array encoding formats in the C# HTTP client generator, allowing arrays to be serialized and deserialized using delimiters such as comma, space, pipe, or newline. The changes span the model, serialization logic, type conversion, and test coverage to ensure correct handling of these encodings.

Array encoding support

  • Introduced an optional encode property to InputModelProperty and related types to specify the desired array encoding (e.g., commaDelimited, spaceDelimited, etc.). This is reflected in the type definitions, model constructors, and JSON serialization/deserialization logic.
  • Updated the type converter (type-converter.ts) to propagate the encode property from SDK model properties into the input model.

Serialization and deserialization logic

  • Added custom serialization and deserialization methods in MrwSerializationTypeDefinition.cs to handle arrays with specified encodings. These methods join or split array elements using the appropriate delimiter and handle both string and primitive element types.

Test coverage

  • Added new tests in EncodeArrayTests.cs to verify correct serialization and deserialization for each supported encoding format (comma, space, pipe, newline).

Implements: #9028

@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 Jan 21, 2026
@github-actions
Copy link
Contributor

No changes needing a change description found.

@radhgupta radhgupta marked this pull request as ready for review January 26, 2026 17:35
Copy link
Contributor

@jorgerangel-msft jorgerangel-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to see the spector tets, but could we also please add some unit tests for the serialization + deserialization code? It would be helpful to see the generated output of that.

Copy link
Contributor

@jorgerangel-msft jorgerangel-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we please add unit tests to see the generated code?

@radhgupta radhgupta added this pull request to the merge queue Jan 30, 2026
Merged via the queue into microsoft:main with commit 20d5b00 Jan 30, 2026
23 checks passed
@radhgupta radhgupta deleted the csv-encoding branch January 30, 2026 21:21
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.

3 participants