forked from loafle/openapi-generator-original
parent
490068ad90
commit
3be89e4c00
@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
|
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
|
||||||
@ -623,8 +624,18 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
if (FEIGN.equals(getLibrary())) {
|
if (FEIGN.equals(getLibrary())) {
|
||||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||||
|
Pattern methodPattern = Pattern.compile("^(.*):([^:]*)$");
|
||||||
for (CodegenOperation op : operationList) {
|
for (CodegenOperation op : operationList) {
|
||||||
String path = op.path;
|
String path = op.path;
|
||||||
|
String method = "";
|
||||||
|
|
||||||
|
// if a custom method is found at the end of the path, cut it off for later
|
||||||
|
Matcher m = methodPattern.matcher(path);
|
||||||
|
if (m.find()) {
|
||||||
|
path = m.group(1);
|
||||||
|
method = m.group(2);
|
||||||
|
}
|
||||||
|
|
||||||
String[] items = path.split("/", -1);
|
String[] items = path.split("/", -1);
|
||||||
|
|
||||||
for (int i = 0; i < items.length; ++i) {
|
for (int i = 0; i < items.length; ++i) {
|
||||||
@ -634,6 +645,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
op.path = StringUtils.join(items, "/");
|
op.path = StringUtils.join(items, "/");
|
||||||
|
// Replace the custom method on the path if one was found earlier
|
||||||
|
if (!method.isEmpty()) {
|
||||||
|
op.path += ":" + method;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1079,4 +1079,31 @@ public class JavaClientCodegenTest {
|
|||||||
.filter(filter)
|
.filter(filter)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCustomMethodParamsAreCamelizedWhenUsingFeign() throws IOException {
|
||||||
|
|
||||||
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
.setGeneratorName("java")
|
||||||
|
.setLibrary(JavaClientCodegen.FEIGN)
|
||||||
|
.setInputSpec("src/test/resources/3_0/issue_7791.yaml")
|
||||||
|
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||||
|
|
||||||
|
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
List<File> files = generator.opts(clientOptInput).generate();
|
||||||
|
|
||||||
|
TestUtils.ensureContainsFile(files, output, "src/main/java/org/openapitools/client/api/DefaultApi.java");
|
||||||
|
|
||||||
|
validateJavaSourceFiles(files);
|
||||||
|
|
||||||
|
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/org/openapitools/client/api/DefaultApi.java"),
|
||||||
|
"@RequestLine(\"POST /events/{eventId}:undelete\")");
|
||||||
|
TestUtils.assertFileNotContains(Paths.get(output + "/src/main/java/org/openapitools/client/api/DefaultApi.java"),
|
||||||
|
"event_id");
|
||||||
|
|
||||||
|
output.deleteOnExit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
openapi: 3.0.1
|
||||||
|
info:
|
||||||
|
title: Custom methods
|
||||||
|
description: "Google custom methods syntax"
|
||||||
|
version: 0.0.1
|
||||||
|
|
||||||
|
paths:
|
||||||
|
/events/{event_id}:undelete:
|
||||||
|
post:
|
||||||
|
operationId: undeleteOperation
|
||||||
|
parameters:
|
||||||
|
- name: event_id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: Event Id
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: success
|
Loading…
x
Reference in New Issue
Block a user