diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs index f02980b787d..12e488d7c9c 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/Utf8JsonReaderExtensions.cs @@ -146,6 +146,37 @@ public static bool TryReadComplexType(this ref Utf8JsonReader reader, string return true; } + public static bool TryReadComplexType(this ref Utf8JsonReader reader, string propertyName, JsonSerializerOptions options, ref IReadOnlyDictionary? value) + { + if (reader.TokenType != JsonTokenType.PropertyName) + { + throw new JsonException(); + } + + if (reader.GetString() != propertyName) + { + return false; + } + + reader.Read(); + if (reader.TokenType != JsonTokenType.StartObject) + { + throw new JsonException(); + } + reader.Read(); + var result = new Dictionary(); + while (reader.TokenType != JsonTokenType.EndObject) + { + var key = reader.GetString() ?? throw new JsonException("Dictionary key cannot be null"); + reader.Read(); + var item = reader.ReadWithConverter(options); + result[key] = item ?? throw new JsonException(); + } + reader.Read(); + value = result; + return true; + } + public static T? ReadWithConverter(this ref Utf8JsonReader reader, JsonSerializerOptions options) { var converter = (JsonConverter)options.GetConverter(typeof(T)); diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TestData/TypeSpecInputExampleConverterTests/LoadOperationExamples/tspCodeModel.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TestData/TypeSpecInputExampleConverterTests/LoadOperationExamples/tspCodeModel.json index 8de71bb388c..034dc234913 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TestData/TypeSpecInputExampleConverterTests/LoadOperationExamples/tspCodeModel.json +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TestData/TypeSpecInputExampleConverterTests/LoadOperationExamples/tspCodeModel.json @@ -6080,6 +6080,14 @@ "$ref": "203" }, "value": { + "$filter": { + "$id": "2000", + "kind": "string", + "type": { + "$ref": "209" + }, + "value": "status eq 'Active'" + }, "description": { "$id": "471", "kind": "string", diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TypeSpecInputExampleConverterTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TypeSpecInputExampleConverterTests.cs index b7892554d22..d12d272cfcd 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TypeSpecInputExampleConverterTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TypeSpecInputExampleConverterTests.cs @@ -103,6 +103,7 @@ static void AssertStorageTaskClientExample(InputClient client) { "location", "westus" }, { "properties.description", "My Storage task" }, { "properties.enabled", true }, + { "properties.$filter", "status eq 'Active'" }, { "properties.action.if.condition", "[[equals(AccessTier, 'Cool')]]" }, { "properties.action.if.operations[0].name", "SetBlobTier" }, { "properties.action.if.operations[0].onFailure", "break" },