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()))"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,6 @@ public class AnotherFakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -131,7 +130,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -183,7 +181,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -235,7 +232,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -287,7 +283,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -343,7 +338,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -405,7 +399,6 @@ public class FakeApi {
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("query", query));
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -461,7 +454,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -545,7 +537,6 @@ public class FakeApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
if (integer != 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)
|
||||
@@ -775,7 +764,6 @@ if (booleanGroup != null)
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -836,7 +824,6 @@ if (booleanGroup != null)
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
if (param != null)
|
||||
@@ -924,7 +911,6 @@ if (param2 != null)
|
||||
localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("ssv", "http", http));
|
||||
localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("csv", "url", url));
|
||||
localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("multi", "context", context));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@ public class FakeClassnameTags123Api {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ public class PetApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -191,7 +189,6 @@ public class PetApi {
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("csv", "status", status));
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -251,7 +248,6 @@ public class PetApi {
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
localVarCollectionQueryParams.addAll(apiClient.parameterToPairs("csv", "tags", tags));
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -309,7 +305,6 @@ public class PetApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -365,7 +360,6 @@ public class PetApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -423,7 +417,6 @@ public class PetApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
if (name != null)
|
||||
@@ -486,7 +479,6 @@ if (status != null)
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
if (additionalMetadata != null)
|
||||
@@ -555,7 +547,6 @@ if (_file != null)
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
if (additionalMetadata != null)
|
||||
|
||||
@@ -73,7 +73,6 @@ public class StoreApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -123,7 +122,6 @@ public class StoreApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -181,7 +179,6 @@ public class StoreApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -238,7 +235,6 @@ public class StoreApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@ public class UserApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -128,7 +127,6 @@ public class UserApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -183,7 +181,6 @@ public class UserApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -239,7 +236,6 @@ public class UserApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -296,7 +292,6 @@ public class UserApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -361,7 +356,6 @@ public class UserApi {
|
||||
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("username", username));
|
||||
localVarQueryParams.addAll(apiClient.parameterToPair("password", password));
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -411,7 +405,6 @@ public class UserApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -473,7 +466,6 @@ public class UserApi {
|
||||
Map<String, String> localVarCookieParams = new HashMap<String, String>();
|
||||
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user