forked from loafle/openapi-generator-original
[JAVA][APACHE] Fix apache http client query parameters (#14020)
* Fix apache http client query parameters * Update samples
This commit is contained in:
@@ -83,9 +83,30 @@ public class {{classname}} {
|
||||
{{javaUtilPrefix}}Map<String, Object> localVarFormParams = new {{javaUtilPrefix}}HashMap<String, Object>();
|
||||
|
||||
{{#queryParams}}
|
||||
{{#isDeepObject}}
|
||||
{{#collectionFormat}}localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(apiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}}));
|
||||
{{/isDeepObject}}
|
||||
{{^isDeepObject}}
|
||||
{{#isExplode}}
|
||||
{{#hasVars}}
|
||||
{{#vars}}
|
||||
{{#isArray}}
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("multi", "{{baseName}}", {{paramName}}.{{getter}}()));
|
||||
{{/isArray}}
|
||||
{{^isArray}}
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("{{baseName}}", {{paramName}}.{{getter}}()));
|
||||
{{/isArray}}
|
||||
{{/vars}}
|
||||
{{/hasVars}}
|
||||
{{^hasVars}}
|
||||
{{#collectionFormat}}localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(apiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}}));
|
||||
{{/hasVars}}
|
||||
{{/isExplode}}
|
||||
{{^isExplode}}
|
||||
{{#collectionFormat}}localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(apiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}}));
|
||||
{{/isExplode}}
|
||||
{{/isDeepObject}}
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}if ({{paramName}} != null)
|
||||
localVarHeaderParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.java.apachehttpclient;
|
||||
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.CodegenConstants;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.TestUtils;
|
||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||
import org.openapitools.codegen.languages.JavaClientCodegen;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.openapitools.codegen.TestUtils.validateJavaSourceFiles;
|
||||
|
||||
public class ApacheHttpClientCodegenTest {
|
||||
|
||||
@Test
|
||||
public void testApacheHttpClientExplodedQueryParamObject() throws IOException {
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.APACHE)
|
||||
.setAdditionalProperties(properties)
|
||||
.setInputSpec("src/test/resources/3_0/issue4808.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
List<File> files = generator.opts(clientOptInput).generate();
|
||||
|
||||
Assert.assertEquals(files.size(), 41);
|
||||
validateJavaSourceFiles(files);
|
||||
|
||||
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/xyz/abcdef/api/DefaultApi.java"),
|
||||
"localVarQueryParams.addAll(apiClient.parameterToPair(\"since\", queryObject.getSince()));",
|
||||
"localVarQueryParams.addAll(apiClient.parameterToPair(\"sinceBuild\", queryObject.getSinceBuild()));",
|
||||
"localVarQueryParams.addAll(apiClient.parameterToPair(\"maxBuilds\", queryObject.getMaxBuilds()));",
|
||||
"localVarQueryParams.addAll(apiClient.parameterToPair(\"maxWaitSecs\", queryObject.getMaxWaitSecs()));"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApacheHttpClientExplodedQueryParamWithArrayProperty() throws IOException {
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(CodegenConstants.API_PACKAGE, "xyz.abcdef.api");
|
||||
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.APACHE)
|
||||
.setAdditionalProperties(properties)
|
||||
.setInputSpec("src/test/resources/3_0/exploded-query-param-array.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
generator.opts(clientOptInput).generate();
|
||||
|
||||
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/xyz/abcdef/api/DefaultApi.java"),
|
||||
"localVarQueryParams.addAll(apiClient.parameterToPair(\"multi\", \"values\", queryObject.getValues()))"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,6 @@ public class AnotherFakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json"
|
||||
};
|
||||
|
||||
@@ -83,7 +83,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -134,7 +133,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"*/*"
|
||||
};
|
||||
@@ -186,7 +184,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"*/*"
|
||||
};
|
||||
@@ -238,7 +235,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"*/*"
|
||||
};
|
||||
@@ -290,7 +286,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"*/*"
|
||||
};
|
||||
@@ -346,7 +341,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -408,7 +402,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -464,7 +457,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json"
|
||||
};
|
||||
@@ -547,7 +539,6 @@ public class FakeApi {
|
||||
|
||||
|
||||
|
||||
|
||||
if (integer != null)
|
||||
localVarFormParams.put("integer", integer);
|
||||
if (int32 != null)
|
||||
@@ -634,7 +625,6 @@ if (paramCallback != null)
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("enum_query_string", enumQueryString));
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("enum_query_integer", enumQueryInteger));
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("enum_query_double", enumQueryDouble));
|
||||
|
||||
if (enumHeaderStringArray != null)
|
||||
localVarHeaderParams.put("enum_header_string_array", apiClient.parameterToString(enumHeaderStringArray));
|
||||
if (enumHeaderString != null)
|
||||
@@ -716,7 +706,6 @@ if (enumFormString != null)
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("required_int64_group", requiredInt64Group));
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("string_group", stringGroup));
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("int64_group", int64Group));
|
||||
|
||||
if (requiredBooleanGroup != null)
|
||||
localVarHeaderParams.put("required_boolean_group", apiClient.parameterToString(requiredBooleanGroup));
|
||||
if (booleanGroup != null)
|
||||
@@ -778,7 +767,6 @@ if (booleanGroup != null)
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -838,7 +826,6 @@ if (booleanGroup != null)
|
||||
|
||||
|
||||
|
||||
|
||||
if (param != null)
|
||||
localVarFormParams.put("param", param);
|
||||
if (param2 != null)
|
||||
@@ -927,7 +914,6 @@ if (param2 != null)
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
|
||||
@@ -76,7 +76,6 @@ public class FakeClassnameTags123Api {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json"
|
||||
};
|
||||
|
||||
@@ -78,7 +78,6 @@ public class PetApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -132,7 +131,6 @@ public class PetApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
if (apiKey != null)
|
||||
localVarHeaderParams.put("api_key", apiClient.parameterToString(apiKey));
|
||||
|
||||
@@ -194,7 +192,6 @@ public class PetApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/xml", "application/json"
|
||||
};
|
||||
@@ -254,7 +251,6 @@ public class PetApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/xml", "application/json"
|
||||
};
|
||||
@@ -312,7 +308,6 @@ public class PetApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/xml", "application/json"
|
||||
};
|
||||
@@ -368,7 +363,6 @@ public class PetApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -425,7 +419,6 @@ public class PetApi {
|
||||
|
||||
|
||||
|
||||
|
||||
if (name != null)
|
||||
localVarFormParams.put("name", name);
|
||||
if (status != null)
|
||||
@@ -488,7 +481,6 @@ if (status != null)
|
||||
|
||||
|
||||
|
||||
|
||||
if (additionalMetadata != null)
|
||||
localVarFormParams.put("additionalMetadata", additionalMetadata);
|
||||
if (_file != null)
|
||||
@@ -557,7 +549,6 @@ if (_file != null)
|
||||
|
||||
|
||||
|
||||
|
||||
if (additionalMetadata != null)
|
||||
localVarFormParams.put("additionalMetadata", additionalMetadata);
|
||||
if (requiredFile != null)
|
||||
|
||||
@@ -76,7 +76,6 @@ public class StoreApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -126,7 +125,6 @@ public class StoreApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/json"
|
||||
};
|
||||
@@ -184,7 +182,6 @@ public class StoreApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/xml", "application/json"
|
||||
};
|
||||
@@ -241,7 +238,6 @@ public class StoreApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/xml", "application/json"
|
||||
};
|
||||
|
||||
@@ -76,7 +76,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -131,7 +130,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -186,7 +184,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -242,7 +239,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -299,7 +295,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/xml", "application/json"
|
||||
};
|
||||
@@ -364,7 +359,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
"application/xml", "application/json"
|
||||
};
|
||||
@@ -414,7 +408,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
@@ -476,7 +469,6 @@ public class UserApi {
|
||||
|
||||
|
||||
|
||||
|
||||
final String[] localVarAccepts = {
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user