mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-19 04:19:13 +00:00
Add option to set Feign version (#1005)
* Add option to set Feign version * add java feign 9x to CI * update usage for Play * fix duplicated artifactId
This commit is contained in:
@@ -60,6 +60,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
public static final String DO_NOT_USE_RX = "doNotUseRx";
|
||||
public static final String USE_PLAY_WS = "usePlayWS";
|
||||
public static final String PLAY_VERSION = "playVersion";
|
||||
public static final String FEIGN_VERSION = "feignVersion";
|
||||
public static final String PARCELABLE_MODEL = "parcelableModel";
|
||||
public static final String USE_RUNTIME_EXCEPTION = "useRuntimeException";
|
||||
|
||||
@@ -67,6 +68,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
public static final String PLAY_25 = "play25";
|
||||
public static final String PLAY_26 = "play26";
|
||||
|
||||
public static final String FEIGN_9 = "9.x";
|
||||
public static final String FEIGN_10 = "10.x";
|
||||
|
||||
public static final String FEIGN = "feign";
|
||||
public static final String GOOGLE_API_CLIENT = "google-api-client";
|
||||
public static final String JERSEY1 = "jersey1";
|
||||
@@ -86,6 +90,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
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 usePlayWS = false;
|
||||
protected String playVersion = PLAY_25;
|
||||
protected String feignVersion = FEIGN_9;
|
||||
protected boolean parcelableModel = false;
|
||||
protected boolean useBeanValidation = false;
|
||||
protected boolean performBeanValidation = false;
|
||||
@@ -106,15 +111,16 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
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_PLAY_WS, "Use Play! Async HTTP client (Play WS API)"));
|
||||
cliOptions.add(CliOption.newString(PLAY_VERSION, "Version of Play! Framework (possible values \"play24\", \"play25\")"));
|
||||
cliOptions.add(CliOption.newString(PLAY_VERSION, "Version of Play! Framework (possible values \"play24\", \"play25\" (default), \"play26\")"));
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library."));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));
|
||||
cliOptions.add(CliOption.newBoolean(FEIGN_VERSION, "Version of OpenFeign: '10.x', '9.x' (default)"));
|
||||
|
||||
supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.8.9. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
|
||||
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.9");
|
||||
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.9. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'");
|
||||
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.8.9");
|
||||
supportedLibraries.put(OKHTTP_GSON, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=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.");
|
||||
@@ -147,7 +153,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java client library.";
|
||||
return "Generates a Java client library (HTTP lib: Jersey (1.x, 2.x), Retrofit (1.x, 2.x), OpenFeign (9.x, 10.x) and more.";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,6 +164,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
|
||||
super.processOpts();
|
||||
|
||||
// RxJava
|
||||
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)) {
|
||||
@@ -169,6 +176,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
if (!useRxJava && !useRxJava2) {
|
||||
additionalProperties.put(DO_NOT_USE_RX, true);
|
||||
}
|
||||
|
||||
// Java Play
|
||||
if (additionalProperties.containsKey(USE_PLAY_WS)) {
|
||||
this.setUsePlayWS(Boolean.valueOf(additionalProperties.get(USE_PLAY_WS).toString()));
|
||||
}
|
||||
@@ -179,6 +188,20 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
additionalProperties.put(PLAY_VERSION, playVersion);
|
||||
|
||||
// OpenFeign
|
||||
if (additionalProperties.containsKey(FEIGN_VERSION)) {
|
||||
this.setFeignVersion(additionalProperties.get(FEIGN_VERSION).toString());
|
||||
|
||||
if ("10.x".equals(feignVersion)) {
|
||||
additionalProperties.put("useFeign10", true);
|
||||
} else if ("9.x".equals(feignVersion)) {
|
||||
// do nothing as 9.x is the default
|
||||
} else {
|
||||
throw new RuntimeException("Ivalid feignOoption '{}'. Must be '10.x' or '9.x'.");
|
||||
}
|
||||
}
|
||||
additionalProperties.put(FEIGN_VERSION, feignVersion);
|
||||
|
||||
if (additionalProperties.containsKey(PARCELABLE_MODEL)) {
|
||||
this.setParcelableModel(Boolean.valueOf(additionalProperties.get(PARCELABLE_MODEL).toString()));
|
||||
}
|
||||
@@ -579,6 +602,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
this.playVersion = playVersion;
|
||||
}
|
||||
|
||||
public void setFeignVersion(String feignVersion) {
|
||||
this.feignVersion = feignVersion;
|
||||
}
|
||||
|
||||
public void setParcelableModel(boolean parcelableModel) {
|
||||
this.parcelableModel = parcelableModel;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user