Skip to content

Commit

Permalink
Skip null form values for Java native request builder (#15036)
Browse files Browse the repository at this point in the history
  • Loading branch information
RInverid authored Mar 29, 2023
1 parent 1cdcaeb commit 3633233
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,15 @@ public class {{classname}} {
{{#formParams}}
{{#isArray}}
for (int i=0; i < {{paramName}}.size(); i++) {
formValues.add(new BasicNameValuePair("{{{baseName}}}", {{paramName}}.get(i).toString()));
if ({{paramName}}.get(i) != null) {
formValues.add(new BasicNameValuePair("{{{baseName}}}", {{paramName}}.get(i).toString()));
}
}
{{/isArray}}
{{^isArray}}
formValues.add(new BasicNameValuePair("{{{baseName}}}", {{paramName}}.toString()));
if ({{paramName}} != null) {
formValues.add(new BasicNameValuePair("{{{baseName}}}", {{paramName}}.toString()));
}
{{/isArray}}
{{/formParams}}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,15 @@ private HttpRequest.Builder testFormIntegerBooleanStringRequestBuilder(Integer i
localVarRequestBuilder.header("Accept", "text/plain");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("integer_form", integerForm.toString()));
formValues.add(new BasicNameValuePair("boolean_form", booleanForm.toString()));
formValues.add(new BasicNameValuePair("string_form", stringForm.toString()));
if (integerForm != null) {
formValues.add(new BasicNameValuePair("integer_form", integerForm.toString()));
}
if (booleanForm != null) {
formValues.add(new BasicNameValuePair("boolean_form", booleanForm.toString()));
}
if (stringForm != null) {
formValues.add(new BasicNameValuePair("string_form", stringForm.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,20 +1032,48 @@ private HttpRequest.Builder testEndpointParametersRequestBuilder(BigDecimal numb
localVarRequestBuilder.header("Accept", "application/json");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("integer", integer.toString()));
formValues.add(new BasicNameValuePair("int32", int32.toString()));
formValues.add(new BasicNameValuePair("int64", int64.toString()));
formValues.add(new BasicNameValuePair("number", number.toString()));
formValues.add(new BasicNameValuePair("float", _float.toString()));
formValues.add(new BasicNameValuePair("double", _double.toString()));
formValues.add(new BasicNameValuePair("string", string.toString()));
formValues.add(new BasicNameValuePair("pattern_without_delimiter", patternWithoutDelimiter.toString()));
formValues.add(new BasicNameValuePair("byte", _byte.toString()));
formValues.add(new BasicNameValuePair("binary", binary.toString()));
formValues.add(new BasicNameValuePair("date", date.toString()));
formValues.add(new BasicNameValuePair("dateTime", dateTime.toString()));
formValues.add(new BasicNameValuePair("password", password.toString()));
formValues.add(new BasicNameValuePair("callback", paramCallback.toString()));
if (integer != null) {
formValues.add(new BasicNameValuePair("integer", integer.toString()));
}
if (int32 != null) {
formValues.add(new BasicNameValuePair("int32", int32.toString()));
}
if (int64 != null) {
formValues.add(new BasicNameValuePair("int64", int64.toString()));
}
if (number != null) {
formValues.add(new BasicNameValuePair("number", number.toString()));
}
if (_float != null) {
formValues.add(new BasicNameValuePair("float", _float.toString()));
}
if (_double != null) {
formValues.add(new BasicNameValuePair("double", _double.toString()));
}
if (string != null) {
formValues.add(new BasicNameValuePair("string", string.toString()));
}
if (patternWithoutDelimiter != null) {
formValues.add(new BasicNameValuePair("pattern_without_delimiter", patternWithoutDelimiter.toString()));
}
if (_byte != null) {
formValues.add(new BasicNameValuePair("byte", _byte.toString()));
}
if (binary != null) {
formValues.add(new BasicNameValuePair("binary", binary.toString()));
}
if (date != null) {
formValues.add(new BasicNameValuePair("date", date.toString()));
}
if (dateTime != null) {
formValues.add(new BasicNameValuePair("dateTime", dateTime.toString()));
}
if (password != null) {
formValues.add(new BasicNameValuePair("password", password.toString()));
}
if (paramCallback != null) {
formValues.add(new BasicNameValuePair("callback", paramCallback.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down Expand Up @@ -1172,9 +1200,13 @@ private HttpRequest.Builder testEnumParametersRequestBuilder(List<String> enumHe

List<NameValuePair> formValues = new ArrayList<>();
for (int i=0; i < enumFormStringArray.size(); i++) {
formValues.add(new BasicNameValuePair("enum_form_string_array", enumFormStringArray.get(i).toString()));
if (enumFormStringArray.get(i) != null) {
formValues.add(new BasicNameValuePair("enum_form_string_array", enumFormStringArray.get(i).toString()));
}
}
if (enumFormString != null) {
formValues.add(new BasicNameValuePair("enum_form_string", enumFormString.toString()));
}
formValues.add(new BasicNameValuePair("enum_form_string", enumFormString.toString()));
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down Expand Up @@ -1585,8 +1617,12 @@ private HttpRequest.Builder testJsonFormDataRequestBuilder(String param, String
localVarRequestBuilder.header("Accept", "application/json");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("param", param.toString()));
formValues.add(new BasicNameValuePair("param2", param2.toString()));
if (param != null) {
formValues.add(new BasicNameValuePair("param", param.toString()));
}
if (param2 != null) {
formValues.add(new BasicNameValuePair("param2", param2.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,12 @@ private HttpRequest.Builder updatePetWithFormRequestBuilder(Long petId, String n
localVarRequestBuilder.header("Accept", "application/json");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("name", name.toString()));
formValues.add(new BasicNameValuePair("status", status.toString()));
if (name != null) {
formValues.add(new BasicNameValuePair("name", name.toString()));
}
if (status != null) {
formValues.add(new BasicNameValuePair("status", status.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,12 @@ private HttpRequest.Builder updatePetWithFormRequestBuilder(Long petId, String n
localVarRequestBuilder.header("Accept", "application/json");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("name", name.toString()));
formValues.add(new BasicNameValuePair("status", status.toString()));
if (name != null) {
formValues.add(new BasicNameValuePair("name", name.toString()));
}
if (status != null) {
formValues.add(new BasicNameValuePair("status", status.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,20 +875,48 @@ private HttpRequest.Builder testEndpointParametersRequestBuilder(BigDecimal numb
localVarRequestBuilder.header("Accept", "application/json");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("integer", integer.toString()));
formValues.add(new BasicNameValuePair("int32", int32.toString()));
formValues.add(new BasicNameValuePair("int64", int64.toString()));
formValues.add(new BasicNameValuePair("number", number.toString()));
formValues.add(new BasicNameValuePair("float", _float.toString()));
formValues.add(new BasicNameValuePair("double", _double.toString()));
formValues.add(new BasicNameValuePair("string", string.toString()));
formValues.add(new BasicNameValuePair("pattern_without_delimiter", patternWithoutDelimiter.toString()));
formValues.add(new BasicNameValuePair("byte", _byte.toString()));
formValues.add(new BasicNameValuePair("binary", binary.toString()));
formValues.add(new BasicNameValuePair("date", date.toString()));
formValues.add(new BasicNameValuePair("dateTime", dateTime.toString()));
formValues.add(new BasicNameValuePair("password", password.toString()));
formValues.add(new BasicNameValuePair("callback", paramCallback.toString()));
if (integer != null) {
formValues.add(new BasicNameValuePair("integer", integer.toString()));
}
if (int32 != null) {
formValues.add(new BasicNameValuePair("int32", int32.toString()));
}
if (int64 != null) {
formValues.add(new BasicNameValuePair("int64", int64.toString()));
}
if (number != null) {
formValues.add(new BasicNameValuePair("number", number.toString()));
}
if (_float != null) {
formValues.add(new BasicNameValuePair("float", _float.toString()));
}
if (_double != null) {
formValues.add(new BasicNameValuePair("double", _double.toString()));
}
if (string != null) {
formValues.add(new BasicNameValuePair("string", string.toString()));
}
if (patternWithoutDelimiter != null) {
formValues.add(new BasicNameValuePair("pattern_without_delimiter", patternWithoutDelimiter.toString()));
}
if (_byte != null) {
formValues.add(new BasicNameValuePair("byte", _byte.toString()));
}
if (binary != null) {
formValues.add(new BasicNameValuePair("binary", binary.toString()));
}
if (date != null) {
formValues.add(new BasicNameValuePair("date", date.toString()));
}
if (dateTime != null) {
formValues.add(new BasicNameValuePair("dateTime", dateTime.toString()));
}
if (password != null) {
formValues.add(new BasicNameValuePair("password", password.toString()));
}
if (paramCallback != null) {
formValues.add(new BasicNameValuePair("callback", paramCallback.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down Expand Up @@ -1012,9 +1040,13 @@ private HttpRequest.Builder testEnumParametersRequestBuilder(List<String> enumHe

List<NameValuePair> formValues = new ArrayList<>();
for (int i=0; i < enumFormStringArray.size(); i++) {
formValues.add(new BasicNameValuePair("enum_form_string_array", enumFormStringArray.get(i).toString()));
if (enumFormStringArray.get(i) != null) {
formValues.add(new BasicNameValuePair("enum_form_string_array", enumFormStringArray.get(i).toString()));
}
}
if (enumFormString != null) {
formValues.add(new BasicNameValuePair("enum_form_string", enumFormString.toString()));
}
formValues.add(new BasicNameValuePair("enum_form_string", enumFormString.toString()));
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down Expand Up @@ -1415,8 +1447,12 @@ private HttpRequest.Builder testJsonFormDataRequestBuilder(String param, String
localVarRequestBuilder.header("Accept", "application/json");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("param", param.toString()));
formValues.add(new BasicNameValuePair("param2", param2.toString()));
if (param != null) {
formValues.add(new BasicNameValuePair("param", param.toString()));
}
if (param2 != null) {
formValues.add(new BasicNameValuePair("param2", param2.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,12 @@ private HttpRequest.Builder updatePetWithFormRequestBuilder(Long petId, String n
localVarRequestBuilder.header("Accept", "application/json");

List<NameValuePair> formValues = new ArrayList<>();
formValues.add(new BasicNameValuePair("name", name.toString()));
formValues.add(new BasicNameValuePair("status", status.toString()));
if (name != null) {
formValues.add(new BasicNameValuePair("name", name.toString()));
}
if (status != null) {
formValues.add(new BasicNameValuePair("status", status.toString()));
}
HttpEntity entity = new UrlEncodedFormEntity(formValues, java.nio.charset.StandardCharsets.UTF_8);
ByteArrayOutputStream formOutputStream = new ByteArrayOutputStream();
try {
Expand Down

0 comments on commit 3633233

Please sign in to comment.