|
37 | 37 | public class KotlinClientCodegen extends AbstractKotlinCodegen {
|
38 | 38 |
|
39 | 39 | protected static final String JVM = "jvm";
|
| 40 | + protected static final String JVM_OKHTTP = "jvm-okhttp"; |
40 | 41 | protected static final String JVM_OKHTTP4 = "jvm-okhttp4";
|
41 | 42 | protected static final String JVM_OKHTTP3 = "jvm-okhttp3";
|
42 |
| - protected static final String RETROFIT2 = "retrofit2"; |
| 43 | + protected static final String JVM_RETROFIT2 = "jvm-retrofit2"; |
43 | 44 | protected static final String MULTIPLATFORM = "multiplatform";
|
44 | 45 |
|
45 | 46 | public static final String DATE_LIBRARY = "dateLibrary";
|
@@ -127,7 +128,7 @@ public KotlinClientCodegen() {
|
127 | 128 |
|
128 | 129 | supportedLibraries.put(JVM_OKHTTP4, "[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.");
|
129 | 130 | supportedLibraries.put(JVM_OKHTTP3, "Platform: Java Virtual Machine. HTTP client: OkHttp 3.12.4 (Android 2.3+ and Java 7+). JSON processing: Moshi 1.8.0.");
|
130 |
| - supportedLibraries.put(RETROFIT2, "Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2."); |
| 131 | + supportedLibraries.put(JVM_RETROFIT2, "Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2."); |
131 | 132 | supportedLibraries.put(MULTIPLATFORM, "Platform: Kotlin multiplatform. HTTP client: Ktor 1.2.4. JSON processing: Kotlinx Serialization: 0.12.0.");
|
132 | 133 |
|
133 | 134 | CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "Library template (sub-template) to use");
|
@@ -194,10 +195,10 @@ public void processOpts() {
|
194 | 195 | switch (getLibrary()) {
|
195 | 196 | case JVM_OKHTTP3:
|
196 | 197 | case JVM_OKHTTP4:
|
197 |
| - processJVMLibrary(infrastructureFolder); |
| 198 | + processJVMOkHttpLibrary(infrastructureFolder); |
198 | 199 | break;
|
199 |
| - case RETROFIT2: |
200 |
| - processRetrofit2Library(infrastructureFolder); |
| 200 | + case JVM_RETROFIT2: |
| 201 | + processJVMRetrofit2Library(infrastructureFolder); |
201 | 202 | break;
|
202 | 203 | case MULTIPLATFORM:
|
203 | 204 | processMultiplatformLibrary(infrastructureFolder);
|
@@ -266,40 +267,46 @@ private void processJava8Date() {
|
266 | 267 | additionalProperties.put(DateLibrary.JAVA8.value, true);
|
267 | 268 | }
|
268 | 269 |
|
269 |
| - private void processRetrofit2Library(String infrastructureFolder) { |
270 |
| - additionalProperties.put(RETROFIT2, true); |
| 270 | + private void processJVMRetrofit2Library(String infrastructureFolder) { |
| 271 | + additionalProperties.put(JVM, true); |
| 272 | + additionalProperties.put(JVM_RETROFIT2, true); |
271 | 273 | supportingFiles.add(new SupportingFile("infrastructure/ApiClient.kt.mustache", infrastructureFolder, "ApiClient.kt"));
|
272 | 274 | supportingFiles.add(new SupportingFile("infrastructure/CollectionFormats.kt.mustache", infrastructureFolder, "CollectionFormats.kt"));
|
273 | 275 | addSupportingSerializerAdapters(infrastructureFolder);
|
274 | 276 | }
|
275 | 277 |
|
276 | 278 | private void addSupportingSerializerAdapters(final String infrastructureFolder) {
|
277 |
| - supportingFiles.add(new SupportingFile("infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt")); |
278 |
| - supportingFiles.add(new SupportingFile("infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt")); |
279 |
| - supportingFiles.add(new SupportingFile("infrastructure/LocalDateAdapter.kt.mustache", infrastructureFolder, "LocalDateAdapter.kt")); |
280 |
| - supportingFiles.add(new SupportingFile("infrastructure/LocalDateTimeAdapter.kt.mustache", infrastructureFolder, "LocalDateTimeAdapter.kt")); |
281 |
| - supportingFiles.add(new SupportingFile("infrastructure/UUIDAdapter.kt.mustache", infrastructureFolder, "UUIDAdapter.kt")); |
282 |
| - |
283 |
| - if (getSerializationLibrary() == SERIALIZATION_LIBRARY_TYPE.gson) { |
284 |
| - supportingFiles.add(new SupportingFile("infrastructure/DateAdapter.kt.mustache", infrastructureFolder, |
285 |
| - "DateAdapter.kt")); |
| 279 | + supportingFiles.add(new SupportingFile("jvm-common/infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt")); |
| 280 | + supportingFiles.add(new SupportingFile("jvm-common/infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt")); |
| 281 | + supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateAdapter.kt.mustache", infrastructureFolder, "LocalDateAdapter.kt")); |
| 282 | + supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateTimeAdapter.kt.mustache", infrastructureFolder, "LocalDateTimeAdapter.kt")); |
| 283 | + |
| 284 | + switch (getSerializationLibrary()) { |
| 285 | + case moshi: |
| 286 | + supportingFiles.add(new SupportingFile("jvm-common/infrastructure/UUIDAdapter.kt.mustache", infrastructureFolder, "UUIDAdapter.kt")); |
| 287 | + break; |
| 288 | + |
| 289 | + case gson: |
| 290 | + supportingFiles.add(new SupportingFile("jvm-common/infrastructure/DateAdapter.kt.mustache", infrastructureFolder, "DateAdapter.kt")); |
| 291 | + break; |
286 | 292 | }
|
287 | 293 | }
|
288 | 294 |
|
289 |
| - private void processJVMLibrary(final String infrastructureFolder) { |
| 295 | + private void processJVMOkHttpLibrary(final String infrastructureFolder) { |
290 | 296 | commonJvmMultiplatformSupportingFiles(infrastructureFolder);
|
291 | 297 | addSupportingSerializerAdapters(infrastructureFolder);
|
292 | 298 |
|
293 | 299 | additionalProperties.put(JVM, true);
|
| 300 | + additionalProperties.put(JVM_OKHTTP, true); |
294 | 301 |
|
295 | 302 | if (JVM_OKHTTP4.equals(getLibrary())) {
|
296 | 303 | additionalProperties.put(JVM_OKHTTP4, true);
|
297 | 304 | } else if (JVM_OKHTTP3.equals(getLibrary())) {
|
298 | 305 | additionalProperties.put(JVM_OKHTTP3, true);
|
299 | 306 | }
|
300 | 307 |
|
301 |
| - supportedLibraries.put(JVM, "A workaround to use the same template folder for both 'jvm-okhttp3' and 'jvm-okhttp4'."); |
302 |
| - setLibrary(JVM); |
| 308 | + supportedLibraries.put(JVM_OKHTTP, "A workaround to use the same template folder for both 'jvm-okhttp3' and 'jvm-okhttp4'."); |
| 309 | + setLibrary(JVM_OKHTTP); |
303 | 310 |
|
304 | 311 | // jvm specific supporting files
|
305 | 312 | supportingFiles.add(new SupportingFile("infrastructure/ApplicationDelegates.kt.mustache", infrastructureFolder, "ApplicationDelegates.kt"));
|
|
0 commit comments