forked from loafle/openapi-generator-original
ISSUE-11242: Fix Java native path param encoding (#11257)
This commit is contained in:
@@ -76,7 +76,7 @@ public class ApiClient {
|
|||||||
* @return URL-encoded representation of the input string.
|
* @return URL-encoded representation of the input string.
|
||||||
*/
|
*/
|
||||||
public static String urlEncode(String s) {
|
public static String urlEncode(String s) {
|
||||||
return URLEncoder.encode(s, UTF_8);
|
return URLEncoder.encode(s, UTF_8).replaceAll("\\+", "%20");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1228,4 +1228,34 @@ public class JavaClientCodegenTest {
|
|||||||
final Path defaultApi = Paths.get(output + "/src/main/java/xyz/abcdef/ApiClient.java");
|
final Path defaultApi = Paths.get(output + "/src/main/java/xyz/abcdef/ApiClient.java");
|
||||||
TestUtils.assertFileContains(defaultApi, "value instanceof Map");
|
TestUtils.assertFileContains(defaultApi, "value instanceof Map");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://github.com/OpenAPITools/openapi-generator/issues/11242
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testNativeClientWhiteSpacePathParamEncoding() throws IOException {
|
||||||
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
properties.put(JavaClientCodegen.JAVA8_MODE, true);
|
||||||
|
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/issue11242.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(), 34);
|
||||||
|
validateJavaSourceFiles(files);
|
||||||
|
|
||||||
|
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\"); }");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
openapi: 3.0.3
|
||||||
|
info:
|
||||||
|
title: Issue 11242 - Path Param encoding
|
||||||
|
description: "White space encoding in path parameters"
|
||||||
|
version: "1.0.0"
|
||||||
|
servers:
|
||||||
|
- url: localhost:8080
|
||||||
|
paths:
|
||||||
|
/api/{someParam}:
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: someParam
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
description: Some parameter.
|
||||||
|
get:
|
||||||
|
operationId: GetSomeParam
|
||||||
|
summary: View some param
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Some return value
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/SomeReturnValue'
|
||||||
|
example:
|
||||||
|
someParam: someValue
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
SomeReturnValue:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- someParam
|
||||||
|
properties:
|
||||||
|
someParam:
|
||||||
|
type: string
|
||||||
@@ -81,7 +81,7 @@ public class ApiClient {
|
|||||||
* @return URL-encoded representation of the input string.
|
* @return URL-encoded representation of the input string.
|
||||||
*/
|
*/
|
||||||
public static String urlEncode(String s) {
|
public static String urlEncode(String s) {
|
||||||
return URLEncoder.encode(s, UTF_8);
|
return URLEncoder.encode(s, UTF_8).replaceAll("\\+", "%20");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class ApiClient {
|
|||||||
* @return URL-encoded representation of the input string.
|
* @return URL-encoded representation of the input string.
|
||||||
*/
|
*/
|
||||||
public static String urlEncode(String s) {
|
public static String urlEncode(String s) {
|
||||||
return URLEncoder.encode(s, UTF_8);
|
return URLEncoder.encode(s, UTF_8).replaceAll("\\+", "%20");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user