forked from loafle/openapi-generator-original
Feature/issue 4698 rxjava2 support (#4743)
* rx2 support * NO_NOT_USE_RX is for internal use only; plus sanity check if both v1 and v2 are specified * minor fixes * one more small fix
This commit is contained in:
@@ -20,6 +20,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);
|
||||
|
||||
public static final String USE_RX_JAVA = "useRxJava";
|
||||
public static final String USE_RX_JAVA2 = "useRxJava2";
|
||||
public static final String DO_NOT_USE_RX = "doNotUseRx";
|
||||
public static final String USE_PLAY24_WS = "usePlay24WS";
|
||||
public static final String PARCELABLE_MODEL = "parcelableModel";
|
||||
|
||||
@@ -28,6 +30,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
|
||||
protected String gradleWrapperPackage = "gradle.wrapper";
|
||||
protected boolean useRxJava = false;
|
||||
protected boolean useRxJava2 = false;
|
||||
protected boolean doNotUseRx = true; // backwards compatibility for swagger configs that specify neither rx1 nor rx2 (mustache does not allow for boolean operators so we need this extra field)
|
||||
protected boolean usePlay24WS = false;
|
||||
protected boolean parcelableModel = false;
|
||||
protected boolean useBeanValidation = false;
|
||||
@@ -43,6 +47,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA2, "Whether to use the RxJava2 adapter with the retrofit2 library."));
|
||||
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
|
||||
cliOptions.add(CliOption.newBoolean(USE_PLAY24_WS, "Use Play! 2.4 Async HTTP client (Play WS API)"));
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library."));
|
||||
@@ -54,7 +59,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.22.2. JSON processing: Jackson 2.7.0");
|
||||
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.6.2. Enable Parcelable modles on Android using '-DparcelableModel=true'");
|
||||
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.");
|
||||
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.2.0. JSON processing: Gson 2.6.1 (Retrofit 2.0.2). Enable the RxJava adapter using '-DuseRxJava=true'. (RxJava 1.1.3)");
|
||||
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.2.0. JSON processing: Gson 2.6.1 (Retrofit 2.0.2). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)");
|
||||
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
libraryOption.setEnum(supportedLibraries);
|
||||
@@ -84,9 +89,17 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA)) {
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA) && additionalProperties.containsKey(USE_RX_JAVA2)) {
|
||||
LOGGER.warn("You specified both RxJava versions 1 and 2 but they are mutually exclusive. Defaulting to v2.");
|
||||
} else if (additionalProperties.containsKey(USE_RX_JAVA)) {
|
||||
this.setUseRxJava(Boolean.valueOf(additionalProperties.get(USE_RX_JAVA).toString()));
|
||||
}
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA2)) {
|
||||
this.setUseRxJava2(Boolean.valueOf(additionalProperties.get(USE_RX_JAVA2).toString()));
|
||||
}
|
||||
if (!useRxJava && !useRxJava2) {
|
||||
additionalProperties.put(DO_NOT_USE_RX, true);
|
||||
}
|
||||
if (additionalProperties.containsKey(USE_PLAY24_WS)) {
|
||||
this.setUsePlay24WS(Boolean.valueOf(additionalProperties.get(USE_PLAY24_WS).toString()));
|
||||
}
|
||||
@@ -335,6 +348,16 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
|
||||
public void setUseRxJava(boolean useRxJava) {
|
||||
this.useRxJava = useRxJava;
|
||||
doNotUseRx = false;
|
||||
}
|
||||
|
||||
public void setUseRxJava2(boolean useRxJava2) {
|
||||
this.useRxJava2 = useRxJava2;
|
||||
doNotUseRx = false;
|
||||
}
|
||||
|
||||
public void setDoNotUseRx(boolean doNotUseRx) {
|
||||
this.doNotUseRx = doNotUseRx;
|
||||
}
|
||||
|
||||
public void setUsePlay24WS(boolean usePlay24WS) {
|
||||
|
||||
Reference in New Issue
Block a user