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..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,14 +462,20 @@ private static Object getSanitizedValues(Object value) { return null; } if (value.getClass().isArray()) { - if (((Object[]) value).length > 0 && ((Object[]) value)[0] instanceof ValuedEnum) { + 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) { - result.add(((ValuedEnum) item).getValue()); + 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) { 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..d1c07d1c1 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 @@ -50,6 +51,27 @@ 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 @@ -131,6 +153,30 @@ 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 +253,24 @@ 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 +303,30 @@ 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 +503,31 @@ class GetQueryParameters implements QueryParameters { @jakarta.annotation.Nullable public TestEnum[] datasets; + @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; + + /** + * 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("parallelDatasetIds", parallelDatasetIds); + allQueryParams.put("expandChildren", expandChildren); + allQueryParams.put("periods", messageAges); return allQueryParams; } }