From 349ec103d0279fd2d58177fd90bc8d7a79855307 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 20 Nov 2024 12:36:41 -0500 Subject: [PATCH 1/3] fix: array query parameters with single entries --- .../Functions.OpenApi/Serialization/OpenApiTypeConverter.cs | 3 ++- .../OpenApi/Serialization/OpenApiTypeConverterTests.cs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs b/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs index 5b7422950d15..7968c054b16b 100644 --- a/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs +++ b/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs @@ -30,7 +30,8 @@ public static JsonNode Convert(string name, string type, object argument) "string" => JsonValue.Create(argument), "array" => argument switch { - string s => JsonArray.Parse(s) as JsonArray, + string s when s.Trim().StartsWith('[') => JsonArray.Parse(s) as JsonArray, + string s => new JsonArray(JsonValue.Create(s)), _ => JsonSerializer.SerializeToNode(argument) as JsonArray }, "integer" => argument switch diff --git a/dotnet/src/Functions/Functions.UnitTests/OpenApi/Serialization/OpenApiTypeConverterTests.cs b/dotnet/src/Functions/Functions.UnitTests/OpenApi/Serialization/OpenApiTypeConverterTests.cs index 9331bb0b55a2..9ec1ee5f3a39 100644 --- a/dotnet/src/Functions/Functions.UnitTests/OpenApi/Serialization/OpenApiTypeConverterTests.cs +++ b/dotnet/src/Functions/Functions.UnitTests/OpenApi/Serialization/OpenApiTypeConverterTests.cs @@ -111,5 +111,7 @@ public void ItShouldConvertCollections() Assert.Equal("[1,2,3]", OpenApiTypeConverter.Convert("id", "array", new Collection() { 1, 2, 3 }).ToJsonString()); Assert.Equal("[1,2,3]", OpenApiTypeConverter.Convert("id", "array", "[1, 2, 3]").ToJsonString()); + + Assert.Equal("[\"createdDate desc\"]", OpenApiTypeConverter.Convert("id", "array", "createdDate desc").ToJsonString()); } } From 9995ff743cbd82a33244582a421cc9d1919b2759 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 20 Nov 2024 12:47:15 -0500 Subject: [PATCH 2/3] fix: compatibility with net standard Signed-off-by: Vincent Biret --- .../Functions.OpenApi/Serialization/OpenApiTypeConverter.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs b/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs index 7968c054b16b..d7a67a4c12e7 100644 --- a/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs +++ b/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs @@ -30,7 +30,11 @@ public static JsonNode Convert(string name, string type, object argument) "string" => JsonValue.Create(argument), "array" => argument switch { +#if NETSTANDARD2_1_OR_GREATER string s when s.Trim().StartsWith('[') => JsonArray.Parse(s) as JsonArray, +#else + string s when s.Trim().StartsWith("[", StringComparison.OrdinalIgnoreCase) => JsonArray.Parse(s) as JsonArray, +#endif string s => new JsonArray(JsonValue.Create(s)), _ => JsonSerializer.SerializeToNode(argument) as JsonArray }, From 1dd6f15d7f237cb3626d31a7f521d70243dd4832 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 20 Nov 2024 12:48:23 -0500 Subject: [PATCH 3/3] chore: linting Signed-off-by: Vincent Biret --- .../Functions.OpenApi/Serialization/OpenApiTypeConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs b/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs index d7a67a4c12e7..dbed711cd3c1 100644 --- a/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs +++ b/dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs @@ -35,7 +35,7 @@ string s when s.Trim().StartsWith('[') => JsonArray.Parse(s) as JsonArray, #else string s when s.Trim().StartsWith("[", StringComparison.OrdinalIgnoreCase) => JsonArray.Parse(s) as JsonArray, #endif - string s => new JsonArray(JsonValue.Create(s)), + string s => [JsonValue.Create(s)], _ => JsonSerializer.SerializeToNode(argument) as JsonArray }, "integer" => argument switch