-
Notifications
You must be signed in to change notification settings - Fork 334
Add support for array encoding with @encode(ArrayEncoding.*) decorator #9430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
No changes needing a change description found. |
e7bb9b0 to
fbbfaf5
Compare
| IsDiscriminator = isDiscriminator; | ||
| IsHttpMetadata = isHttpMetadata; | ||
| SerializationOptions = serializationOptions; | ||
| Encode = encode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should follow the same pattern we use for other encoding formats. We can define a new ArrayKnownEncoding enum and add each of the possible values and then flow this through to a SerializationFormat. See https://github.com/microsoft/typespec/blob/main/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/TypeFactory.cs#L340
| public bool IsNullable { get; } | ||
| public bool IsDiscriminator { get; } | ||
| public bool IsHttpMetadata { get; } | ||
| public string? Encode { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would instead be the _serializationFormat on the PropertyProvider.
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
encodeproperty toInputModelPropertyand 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.type-converter.ts) to propagate theencodeproperty from SDK model properties into the input model.Serialization and deserialization logic
MrwSerializationTypeDefinition.csto 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
EncodeArrayTests.csto verify correct serialization and deserialization for each supported encoding format (comma, space, pipe, newline).Implements: #9028