[BUG][java][resttemplate] Fix NPE when query param with value null is exploded (#17568)

* Fix NPE when query param with value null is exploded

* Polish

* Add test

* Update tests

* Add integration test
This commit is contained in:
Jorge Rodríguez Martín
2024-01-10 16:39:41 +01:00
committed by GitHub
parent d0e533d573
commit 61c40474af
17 changed files with 150 additions and 56 deletions

View File

@@ -84,7 +84,7 @@ public class QueryApi {
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_nonref_string_query", enumNonrefStringQuery));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "enum_ref_string_query", enumRefStringQuery));
final String[] localVarAccepts = {
"text/plain"
@@ -134,7 +134,7 @@ public class QueryApi {
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "datetime_query", datetimeQuery));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "date_query", dateQuery));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "string_query", stringQuery));
final String[] localVarAccepts = {
"text/plain"
@@ -184,7 +184,7 @@ public class QueryApi {
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "integer_query", integerQuery));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "boolean_query", booleanQuery));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "string_query", stringQuery));
final String[] localVarAccepts = {
"text/plain"
@@ -227,13 +227,15 @@ public class QueryApi {
final MultiValueMap<String, String> localVarCookieParams = new LinkedMultiValueMap<String, String>();
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", queryObject.getId()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "name", queryObject.getName()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "category", queryObject.getCategory()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "photoUrls", queryObject.getPhotoUrls()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "tags", queryObject.getTags()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", queryObject.getStatus()));
if (queryObject != null) {
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", queryObject.getId()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "name", queryObject.getName()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "category", queryObject.getCategory()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "photoUrls", queryObject.getPhotoUrls()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "tags", queryObject.getTags()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", queryObject.getStatus()));
}
final String[] localVarAccepts = {
"text/plain"
@@ -277,7 +279,7 @@ public class QueryApi {
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "query_object", queryObject));
final String[] localVarAccepts = {
"text/plain"
@@ -320,8 +322,10 @@ public class QueryApi {
final MultiValueMap<String, String> localVarCookieParams = new LinkedMultiValueMap<String, String>();
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "values", queryObject.getValues()));
if (queryObject != null) {
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "values", queryObject.getValues()));
}
final String[] localVarAccepts = {
"text/plain"
@@ -364,13 +368,15 @@ public class QueryApi {
final MultiValueMap<String, String> localVarCookieParams = new LinkedMultiValueMap<String, String>();
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", queryObject.getId()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "name", queryObject.getName()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "category", queryObject.getCategory()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "photoUrls", queryObject.getPhotoUrls()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "tags", queryObject.getTags()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", queryObject.getStatus()));
if (queryObject != null) {
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", queryObject.getId()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "name", queryObject.getName()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "category", queryObject.getCategory()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "photoUrls", queryObject.getPhotoUrls()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "tags", queryObject.getTags()));
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", queryObject.getStatus()));
}
final String[] localVarAccepts = {
"text/plain"
@@ -414,7 +420,7 @@ public class QueryApi {
final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();
localVarQueryParams.putAll(apiClient.parameterToMultiValueMap(null, "query_object", queryObject));
final String[] localVarAccepts = {
"text/plain"

View File

@@ -14,13 +14,15 @@
package org.openapitools.client;
import org.junit.Assert;
import org.openapitools.client.api.*;
import org.openapitools.client.model.*;
import org.junit.Test;
import org.junit.Ignore;
import org.openapitools.client.api.BodyApi;
import org.openapitools.client.api.QueryApi;
import org.openapitools.client.model.Category;
import org.openapitools.client.model.Pet;
import java.io.IOException;
import java.util.*;
import java.util.Arrays;
import static org.junit.Assert.assertNotNull;
/**
@@ -43,7 +45,7 @@ public class CustomTest {
photoUrls(Arrays.asList(new String[]{"http://a.com", "http://b.com"})).category(new Category().id(987L).name("new category"));
Pet p = bodyApi.testEchoBodyPet(pet);
Assert.assertNotNull(p);
assertNotNull(p);
Assert.assertEquals("Hello World", p.getName());
Assert.assertEquals(Long.valueOf(12345L), p.getId());
@@ -51,4 +53,9 @@ public class CustomTest {
Pet p2 = bodyApi.testEchoBodyPet(null);
Assert.assertNull(p2);
}
@Test
public void testQueryParamsExploded_whenQueryParamIsNull() {
assertNotNull(api.testQueryStyleFormExplodeTrueObject(null));
}
}