Disable jdk8 when using responseWrapper (#2873)

Fix #2872
This commit is contained in:
Thibault Duperron 2019-05-15 15:12:00 +02:00 committed by William Cheng
parent cbe39ba881
commit c3efb91e31
2 changed files with 41 additions and 24 deletions

View File

@ -21,6 +21,7 @@ import com.samskivert.mustache.Mustache;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
@ -36,6 +37,7 @@ import java.util.*;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.openapitools.codegen.utils.StringUtils.camelize;
public class SpringCodegen extends AbstractJavaCodegen
@ -377,7 +379,7 @@ public class SpringCodegen extends AbstractJavaCodegen
if (this.java8) {
additionalProperties.put("javaVersion", "1.8");
if (!SPRING_CLOUD_LIBRARY.equals(library)) {
additionalProperties.put("jdk8", "true");
additionalProperties.put("jdk8", true);
}
if (this.async) {
additionalProperties.put(RESPONSE_WRAPPER, "CompletableFuture");
@ -395,29 +397,32 @@ public class SpringCodegen extends AbstractJavaCodegen
// Some well-known Spring or Spring-Cloud response wrappers
switch (this.responseWrapper) {
case "Future":
case "Callable":
case "CompletableFuture":
additionalProperties.put(RESPONSE_WRAPPER, "java.util.concurrent." + this.responseWrapper);
break;
case "ListenableFuture":
additionalProperties.put(RESPONSE_WRAPPER, "org.springframework.util.concurrent.ListenableFuture");
break;
case "DeferredResult":
additionalProperties.put(RESPONSE_WRAPPER, "org.springframework.web.context.request.async.DeferredResult");
break;
case "HystrixCommand":
additionalProperties.put(RESPONSE_WRAPPER, "com.netflix.hystrix.HystrixCommand");
break;
case "RxObservable":
additionalProperties.put(RESPONSE_WRAPPER, "rx.Observable");
break;
case "RxSingle":
additionalProperties.put(RESPONSE_WRAPPER, "rx.Single");
break;
default:
break;
if (isNotEmpty(this.responseWrapper)) {
additionalProperties.put("jdk8", false);
switch (this.responseWrapper) {
case "Future":
case "Callable":
case "CompletableFuture":
additionalProperties.put(RESPONSE_WRAPPER, "java.util.concurrent." + this.responseWrapper);
break;
case "ListenableFuture":
additionalProperties.put(RESPONSE_WRAPPER, "org.springframework.util.concurrent.ListenableFuture");
break;
case "DeferredResult":
additionalProperties.put(RESPONSE_WRAPPER, "org.springframework.web.context.request.async.DeferredResult");
break;
case "HystrixCommand":
additionalProperties.put(RESPONSE_WRAPPER, "com.netflix.hystrix.HystrixCommand");
break;
case "RxObservable":
additionalProperties.put(RESPONSE_WRAPPER, "rx.Observable");
break;
case "RxSingle":
additionalProperties.put(RESPONSE_WRAPPER, "rx.Single");
break;
default:
break;
}
}
// add lambda for mustache templates

View File

@ -25,6 +25,8 @@ import org.openapitools.codegen.languages.SpringCodegen;
import org.testng.Assert;
import org.testng.annotations.Test;
import static org.openapitools.codegen.languages.SpringCodegen.RESPONSE_WRAPPER;
public class SpringCodegenTest {
@Test
@ -110,4 +112,14 @@ public class SpringCodegenTest {
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.TITLE), "someTest");
Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.SERVER_PORT), "8088");
}
@Test
public void interfaceDefaultImplDisableWithReponseWrapper() {
final SpringCodegen codegen = new SpringCodegen();
codegen.additionalProperties().put(SpringCodegen.JAVA_8, true);
codegen.additionalProperties().put(RESPONSE_WRAPPER, "aWrapper");
codegen.processOpts();
Assert.assertEquals(codegen.additionalProperties().get("jdk8"), false);
}
}