forked from loafle/openapi-generator-original
Properly encode exploded query params in url (#11682)
This commit is contained in:
parent
79970228e6
commit
7dcfe62dee
@ -318,7 +318,19 @@ public class {{classname}} {
|
|||||||
}
|
}
|
||||||
{{/isDeepObject}}
|
{{/isDeepObject}}
|
||||||
{{^isDeepObject}}
|
{{^isDeepObject}}
|
||||||
|
{{#isExplode}}
|
||||||
|
{{#hasVars}}
|
||||||
|
{{#vars}}
|
||||||
|
localVarQueryParams.addAll(ApiClient.parameterToPairs("{{baseName}}", {{paramName}}.{{getter}}()));
|
||||||
|
{{/vars}}
|
||||||
|
{{/hasVars}}
|
||||||
|
{{^hasVars}}
|
||||||
localVarQueryParams.addAll(ApiClient.parameterToPairs("{{baseName}}", {{paramName}}));
|
localVarQueryParams.addAll(ApiClient.parameterToPairs("{{baseName}}", {{paramName}}));
|
||||||
|
{{/hasVars}}
|
||||||
|
{{/isExplode}}
|
||||||
|
{{^isExplode}}
|
||||||
|
localVarQueryParams.addAll(ApiClient.parameterToPairs("{{baseName}}", {{paramName}}));
|
||||||
|
{{/isExplode}}
|
||||||
{{/isDeepObject}}
|
{{/isDeepObject}}
|
||||||
{{/collectionFormat}}
|
{{/collectionFormat}}
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
|
@ -1276,4 +1276,37 @@ public class JavaClientCodegenTest {
|
|||||||
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/xyz/abcdef/ApiClient.java"),
|
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/xyz/abcdef/ApiClient.java"),
|
||||||
"public static String urlEncode(String s) { return URLEncoder.encode(s, UTF_8).replaceAll(\"\\\\+\", \"%20\"); }");
|
"public static String urlEncode(String s) { return URLEncoder.encode(s, UTF_8).replaceAll(\"\\\\+\", \"%20\"); }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://github.com/OpenAPITools/openapi-generator/issues/4808
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testNativeClientExplodedQueryParamObject() 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.NATIVE)
|
||||||
|
.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(), 38);
|
||||||
|
validateJavaSourceFiles(files);
|
||||||
|
|
||||||
|
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/xyz/abcdef/api/DefaultApi.java"),
|
||||||
|
"localVarQueryParams.addAll(ApiClient.parameterToPairs(\"since\", queryObject.getSince()));",
|
||||||
|
"localVarQueryParams.addAll(ApiClient.parameterToPairs(\"sinceBuild\", queryObject.getSinceBuild()));",
|
||||||
|
"localVarQueryParams.addAll(ApiClient.parameterToPairs(\"maxBuilds\", queryObject.getMaxBuilds()));",
|
||||||
|
"localVarQueryParams.addAll(ApiClient.parameterToPairs(\"maxWaitSecs\", queryObject.getMaxWaitSecs()));"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
info:
|
||||||
|
title: Issue 11242 - exploded query params
|
||||||
|
description: "Exploded query params"
|
||||||
|
version: "1.0.0"
|
||||||
|
servers:
|
||||||
|
- url: localhost:8080
|
||||||
|
paths:
|
||||||
|
/api:
|
||||||
|
get:
|
||||||
|
operationId: GetSomeValue
|
||||||
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: QueryObject
|
||||||
|
explode: true
|
||||||
|
style: form
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
since:
|
||||||
|
type: string
|
||||||
|
sinceBuild:
|
||||||
|
type: string
|
||||||
|
maxBuilds:
|
||||||
|
type: integer
|
||||||
|
maxWaitSecs:
|
||||||
|
type: integer
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Some return value
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/SomeReturnValue'
|
||||||
|
example:
|
||||||
|
someValue: value
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
SomeReturnValue:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- someValue
|
||||||
|
properties:
|
||||||
|
someValue:
|
||||||
|
type: string
|
Loading…
x
Reference in New Issue
Block a user