From 96f9f311b4f16766bd95776341597c9b3d5a5d74 Mon Sep 17 00:00:00 2001 From: Espen Asphaug Myran Date: Tue, 18 Nov 2025 14:24:09 +0100 Subject: [PATCH 1/5] fix: allow arrays of all supported types in getSanitizedValues --- .../main/java/com/microsoft/kiota/RequestInformation.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java b/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java index 6ef770bc5..9001df459 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java @@ -462,10 +462,14 @@ private static Object getSanitizedValues(Object value) { return null; } if (value.getClass().isArray()) { - if (((Object[]) value).length > 0 && ((Object[]) value)[0] instanceof ValuedEnum) { + if (((Object[]) value).length > 0) { + if (((Object[]) value)[0].getClass().isArray()) { + throw new IllegalArgumentException("multidimensional arrays are not supported"); + } + final ArrayList result = new ArrayList<>(); for (final Object item : (Object[]) value) { - result.add(((ValuedEnum) item).getValue()); + result.add(getSanitizedValues(item).toString()); } return result; } From 4ecee97c4c83c397dc587aa070863252f347660a Mon Sep 17 00:00:00 2001 From: Espen Asphaug Myran Date: Tue, 18 Nov 2025 14:24:52 +0100 Subject: [PATCH 2/5] test: add a few sanity checks for arrays of special types --- .../kiota/RequestInformationTest.java | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java b/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java index 24931ef5e..cc540d4b1 100644 --- a/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java +++ b/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.UUID; class RequestInformationTest { @Test @@ -131,6 +132,29 @@ void SetsPathParametersOfPeriodAndDurationType() { assertTrue(uriResult.toString().contains("seatingDuration='PT30M'")); } + + @Test + void SetsQueryParametersOfPeriodAndDurationTypedArray() throws IllegalStateException, URISyntaxException { + // Arrange as the request builders would + final RequestInformation requestInfo = new RequestInformation(); + requestInfo.httpMethod = HttpMethod.GET; + requestInfo.urlTemplate = "http://localhost/{?periods}"; + + final GetQueryParameters queryParameters = new GetQueryParameters(); + queryParameters.messageAges = new PeriodAndDuration[] { + PeriodAndDuration.parse("PT30M"), + PeriodAndDuration.parse("PT20M"), + PeriodAndDuration.parse("PT1H20M") + }; + + // Act + requestInfo.addQueryParameters(queryParameters); + + // Assert + final URI uri = requestInfo.getUri(); + assertEquals("http://localhost/?periods=PT30M,PT20M,PT1H20M", uri.toString()); + } + @Test void ExpandQueryParametersAfterPathParams() { // Arrange as the request builders would @@ -207,6 +231,26 @@ void SetsPathParametersOfBooleanType() { assertTrue(uriResult.toString().contains("count=true")); } + @Test + void SetsQueryParametersOfBooleanTypedArray() throws IllegalStateException, URISyntaxException { + // Arrange as the request builders would + final RequestInformation requestInfo = new RequestInformation(); + requestInfo.httpMethod = HttpMethod.GET; + requestInfo.urlTemplate = "http://localhost/{?expandChildren}"; + + final GetQueryParameters queryParameters = new GetQueryParameters(); + queryParameters.expandChildren = new Boolean[] { + true, false, true, true + }; + + // Act + requestInfo.addQueryParameters(queryParameters); + + // Assert + final URI uri = requestInfo.getUri(); + assertEquals("http://localhost/?expandChildren=true,false,true,true", uri.toString()); + } + @Test void SetsPathParametersOfUUIDType() { // Arrange as the request builders would @@ -239,6 +283,28 @@ void SetsQueryParametersOfUUIDType() { assertTrue(uriResult.toString().contains("?id=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")); } + @Test + void SetsQueryParametersOfUUIDTypedArray() throws IllegalStateException, URISyntaxException { + // Arrange as the request builders would + final RequestInformation requestInfo = new RequestInformation(); + requestInfo.httpMethod = HttpMethod.GET; + requestInfo.urlTemplate = "http://localhost/{?datasetIds}"; + + final GetQueryParameters queryParameters = new GetQueryParameters(); + queryParameters.datasetIds = new UUID[] { + UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"), + UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e") + }; + + // Act + requestInfo.addQueryParameters(queryParameters); + + // Assert + final URI uri = requestInfo.getUri(); + assertEquals("http://localhost/?datasetIds=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e,a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e", uri.toString()); + } + + @Test void SetsParsableContent() { // Arrange as the request builders would @@ -415,12 +481,25 @@ class GetQueryParameters implements QueryParameters { @jakarta.annotation.Nullable public TestEnum[] datasets; + @jakarta.annotation.Nullable public UUID[] datasetIds; + + /** Per-dataset boolean indicating whether to resolve its child datasets */ + @jakarta.annotation.Nullable public Boolean[] expandChildren; + + /** + * Minimum message ages as duration, per dataset + */ + @jakarta.annotation.Nullable public PeriodAndDuration[] messageAges; + @jakarta.annotation.Nonnull public Map toQueryParameters() { - final Map allQueryParams = new HashMap(); + final Map allQueryParams = new HashMap<>(); allQueryParams.put("%24select", select); allQueryParams.put("%24search", search); allQueryParams.put("dataset", dataset); allQueryParams.put("datasets", datasets); + allQueryParams.put("datasetIds", datasetIds); + allQueryParams.put("expandChildren", expandChildren); + allQueryParams.put("periods", messageAges); return allQueryParams; } } From beda3d684612d64c9bef3071fea7877bb954a653 Mon Sep 17 00:00:00 2001 From: Espen Asphaug Myran Date: Tue, 18 Nov 2025 14:52:01 +0100 Subject: [PATCH 3/5] style: improve readability of array values in getSanitizedValues --- .../java/com/microsoft/kiota/RequestInformation.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java b/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java index 9001df459..be16d49e8 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/RequestInformation.java @@ -462,18 +462,20 @@ private static Object getSanitizedValues(Object value) { return null; } if (value.getClass().isArray()) { - if (((Object[]) value).length > 0) { - if (((Object[]) value)[0].getClass().isArray()) { + final Object[] values = (Object[]) value; + + if (values.length > 0) { + if (values[0].getClass().isArray()) { throw new IllegalArgumentException("multidimensional arrays are not supported"); } final ArrayList result = new ArrayList<>(); - for (final Object item : (Object[]) value) { + for (final Object item : values) { result.add(getSanitizedValues(item).toString()); } return result; } - return Arrays.asList((Object[]) value); + return Arrays.asList(values); } else if (value instanceof ValuedEnum) { return ((ValuedEnum) value).getValue(); } else if (value instanceof UUID) { From 12e40eb3bc02574273ef544078a33df4a7503126 Mon Sep 17 00:00:00 2001 From: Espen Asphaug Myran Date: Tue, 18 Nov 2025 14:53:13 +0100 Subject: [PATCH 4/5] test: assert IllegalArgumentException is thrown when a multidimensional array is passed --- .../kiota/RequestInformationTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java b/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java index cc540d4b1..394f8b786 100644 --- a/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java +++ b/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java @@ -51,6 +51,23 @@ void BuildsUrlOnProvidedBaseUrl() { assertEquals("http://localhost/users", result.toString()); } + @Test + void ThrowsIllegalArgumentWhenMultidimensionalQueryParameterIsSet() { + // Arrange as the request builders would + final RequestInformation requestInfo = new RequestInformation(); + requestInfo.httpMethod = HttpMethod.GET; + requestInfo.urlTemplate = "{+baseurl}/users{?datasetIds}"; + final GetQueryParameters queryParameters = new GetQueryParameters(); + queryParameters.parallelDatasetIds = new UUID[][] { + {UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")}, + {UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")} + }; + + // Assert + var exception = assertThrows(IllegalArgumentException.class, () -> requestInfo.addQueryParameters(queryParameters)); + assertTrue(exception.getMessage().contains("multidimensional arrays are not supported")); + } + @Test void SetsPathParametersOfDateTimeOffsetType() { // Arrange as the request builders would @@ -483,6 +500,11 @@ class GetQueryParameters implements QueryParameters { @jakarta.annotation.Nullable public UUID[] datasetIds; + /** + * Search by dataset ids in parallel (or something like that) + */ + @jakarta.annotation.Nullable public UUID[][] parallelDatasetIds; + /** Per-dataset boolean indicating whether to resolve its child datasets */ @jakarta.annotation.Nullable public Boolean[] expandChildren; @@ -491,6 +513,7 @@ class GetQueryParameters implements QueryParameters { */ @jakarta.annotation.Nullable public PeriodAndDuration[] messageAges; + @jakarta.annotation.Nonnull public Map toQueryParameters() { final Map allQueryParams = new HashMap<>(); allQueryParams.put("%24select", select); @@ -498,6 +521,7 @@ class GetQueryParameters implements QueryParameters { allQueryParams.put("dataset", dataset); allQueryParams.put("datasets", datasets); allQueryParams.put("datasetIds", datasetIds); + allQueryParams.put("parallelDatasetIds", parallelDatasetIds); allQueryParams.put("expandChildren", expandChildren); allQueryParams.put("periods", messageAges); return allQueryParams; From d06dc71ef4ed8db92b13dafc6e92c84704cd3c4f Mon Sep 17 00:00:00 2001 From: Espen Asphaug Myran Date: Tue, 18 Nov 2025 15:29:20 +0100 Subject: [PATCH 5/5] style: apply spotlessApply changes affecting test file --- .../kiota/RequestInformationTest.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java b/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java index 394f8b786..d1c07d1c1 100644 --- a/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java +++ b/components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java @@ -58,13 +58,17 @@ void ThrowsIllegalArgumentWhenMultidimensionalQueryParameterIsSet() { requestInfo.httpMethod = HttpMethod.GET; requestInfo.urlTemplate = "{+baseurl}/users{?datasetIds}"; final GetQueryParameters queryParameters = new GetQueryParameters(); - queryParameters.parallelDatasetIds = new UUID[][] { - {UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")}, - {UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")} - }; + queryParameters.parallelDatasetIds = + new UUID[][] { + {UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")}, + {UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e")} + }; // Assert - var exception = assertThrows(IllegalArgumentException.class, () -> requestInfo.addQueryParameters(queryParameters)); + var exception = + assertThrows( + IllegalArgumentException.class, + () -> requestInfo.addQueryParameters(queryParameters)); assertTrue(exception.getMessage().contains("multidimensional arrays are not supported")); } @@ -149,20 +153,21 @@ void SetsPathParametersOfPeriodAndDurationType() { assertTrue(uriResult.toString().contains("seatingDuration='PT30M'")); } - @Test - void SetsQueryParametersOfPeriodAndDurationTypedArray() throws IllegalStateException, URISyntaxException { + void SetsQueryParametersOfPeriodAndDurationTypedArray() + throws IllegalStateException, URISyntaxException { // Arrange as the request builders would final RequestInformation requestInfo = new RequestInformation(); requestInfo.httpMethod = HttpMethod.GET; requestInfo.urlTemplate = "http://localhost/{?periods}"; final GetQueryParameters queryParameters = new GetQueryParameters(); - queryParameters.messageAges = new PeriodAndDuration[] { - PeriodAndDuration.parse("PT30M"), - PeriodAndDuration.parse("PT20M"), - PeriodAndDuration.parse("PT1H20M") - }; + queryParameters.messageAges = + new PeriodAndDuration[] { + PeriodAndDuration.parse("PT30M"), + PeriodAndDuration.parse("PT20M"), + PeriodAndDuration.parse("PT1H20M") + }; // Act requestInfo.addQueryParameters(queryParameters); @@ -256,9 +261,7 @@ void SetsQueryParametersOfBooleanTypedArray() throws IllegalStateException, URIS requestInfo.urlTemplate = "http://localhost/{?expandChildren}"; final GetQueryParameters queryParameters = new GetQueryParameters(); - queryParameters.expandChildren = new Boolean[] { - true, false, true, true - }; + queryParameters.expandChildren = new Boolean[] {true, false, true, true}; // Act requestInfo.addQueryParameters(queryParameters); @@ -308,20 +311,22 @@ void SetsQueryParametersOfUUIDTypedArray() throws IllegalStateException, URISynt requestInfo.urlTemplate = "http://localhost/{?datasetIds}"; final GetQueryParameters queryParameters = new GetQueryParameters(); - queryParameters.datasetIds = new UUID[] { - UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"), - UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e") - }; + queryParameters.datasetIds = + new UUID[] { + UUID.fromString("f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e"), + UUID.fromString("a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e") + }; // Act requestInfo.addQueryParameters(queryParameters); // Assert final URI uri = requestInfo.getUri(); - assertEquals("http://localhost/?datasetIds=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e,a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e", uri.toString()); + assertEquals( + "http://localhost/?datasetIds=f0f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e,a2f351e7-8e5f-4d0e-8f2a-7b5e4b6f4f3e", + uri.toString()); } - @Test void SetsParsableContent() { // Arrange as the request builders would @@ -513,7 +518,6 @@ class GetQueryParameters implements QueryParameters { */ @jakarta.annotation.Nullable public PeriodAndDuration[] messageAges; - @jakarta.annotation.Nonnull public Map toQueryParameters() { final Map allQueryParams = new HashMap<>(); allQueryParams.put("%24select", select);