Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin client: add volley library support #10253

Merged
merged 114 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
c5a6b1f
Add basic jvm-volley folder to enable it as a library
alister995199 Jul 12, 2021
8862438
Add JVM_VOLLEY to the KotlinClientCodegen as a library option (using …
Jul 13, 2021
f9c2084
Temporary checkin of generated code and kotlinfied version for use in…
alister995199 Jul 13, 2021
6b33c39
Added Kotlin-ified api invoker and request objects, update Kotlin cli…
Jul 14, 2021
5529173
Add Android specific build.gradle mustache file to jvm-volley library
Jul 14, 2021
76dd872
Hardcode SDK version and build tools version in build.gradle template…
Jul 14, 2021
27ff848
Add Android manifest to generated code
Jul 14, 2021
a94dcd3
Add Kotlin dependencies and plugins to build gradle template
Jul 15, 2021
732b998
WIP: Create basic API templating for jvm-volley
Jul 15, 2021
2cf5f75
Add ApiException and parameter validation, create path variable using…
Jul 15, 2021
6cf8fff
Build queryParams and headerParams
Jul 15, 2021
58b9356
Add VolleyRequest template
Jul 16, 2021
6ced4a6
WIP: Injecting context and default API invoker into APIs (non compiling)
Jul 16, 2021
6b82587
Add DefaultInvoker stub and update API to inject context
Jul 19, 2021
29b2221
Add request queue generation to the DefaultInvoker
Jul 19, 2021
78afec7
Fix up compile errors in the invoker
Jul 19, 2021
b43c757
Cleanup unrequired templates
Jul 19, 2021
7ad0174
Update templates
alister995199 Jul 19, 2021
579e525
Add constructor overloads to inject stack or network into request queue
Jul 19, 2021
3666643
Merge branch 'master' of https://github.com/alisters/openapi-generator
Jul 19, 2021
b2c6ca9
Fix compile errors with request queue generation
Jul 19, 2021
2412a1e
Fix compile errors
Jul 20, 2021
6f672a7
Al'll fix it for you.....
alister995199 Jul 20, 2021
fafc0c9
WIP compile fixes
Jul 20, 2021
3cdc80c
More compile fixes
Jul 20, 2021
65465af
Generate to java directory and kotlin-ify auth code
alister995199 Jul 20, 2021
7dea22c
More syntax fixes in templates
alister995199 Jul 20, 2021
8792ed9
Almost left it in a working state, fixing that .... now...
alister995199 Jul 20, 2021
331e675
Switch builder method based on model existence constraints - body and…
alister995199 Jul 21, 2021
12f0578
Add coroutine logic to APIs and pass through listeners to the request…
Jul 21, 2021
1e993c5
Use reflection and type tokens to work around clazz issues on generics
alister995199 Jul 21, 2021
6eddbe4
Add POST, PATCH and PUT to RequestFactory
Jul 21, 2021
ac5559f
More templating magic
Jul 22, 2021
760da51
Fix Steve, the human compiler's errors again !
alister995199 Jul 22, 2021
e30caab
Add CLI option for generating room models
Jul 23, 2021
4775389
Configure the room model package
Jul 23, 2021
bbc3196
Add initial room model templating and generation
Jul 23, 2021
bd9a408
Add room model generation implementation
Jul 26, 2021
f43c53c
Implement toRoom function on models to convert model to room model
Jul 27, 2021
18d119a
Bug fixes, transformers to and from room models
Jul 29, 2021
b54a372
Add query parameters to URL generation
Jul 29, 2021
b6205bf
Fix issues with gson type conversion, add type adapters to gson instance
Jul 30, 2021
62b72d4
Fix issues with older API versions and Java8 libraries,
Aug 3, 2021
808bbfa
Add request factory interface
Aug 3, 2021
b1b785a
API template tidy up
Aug 5, 2021
d9f43c0
Update IRequestFactory to include companion object, minor tidy ups
Aug 9, 2021
20df397
Remove @Keep annotations from room templates
Aug 9, 2021
bd0eb7a
Rename toRoomModel and toApiModel functions
Aug 11, 2021
19b20fd
Add empty companion object to generated room model
Aug 12, 2021
67cbfe6
Add ITransformStorage interface to allow polymorphic transforms to ro…
alister995199 Aug 13, 2021
89ce073
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
alister995199 Aug 16, 2021
39b4b6b
Add content type into GsonRequest
Aug 17, 2021
f2c2195
Merge branch 'master' of https://github.com/alisters/openapi-generator
Aug 17, 2021
cd28b20
Move gson serialization of request body into GsonRequest
Aug 17, 2021
bd43b15
Update request factory to take header factories
alister995199 Aug 23, 2021
80a5ce6
Remove the generated comparision code
alister995199 Aug 23, 2021
70e3b0f
Move the generateRoomModels switch into the KotlinClientCodegen class
Aug 26, 2021
6ee9414
Move room model generation out of default generator
alister995199 Aug 26, 2021
789dcb2
Updates for auth
alister995199 Aug 26, 2021
0def1ef
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
alister995199 Aug 26, 2021
197206d
Finalise removal of kotlin elements from default generator
alister995199 Aug 26, 2021
4825ef9
Hoist room model logic out of abstractKotlin into kotlin client codegen
alister995199 Aug 26, 2021
97d2774
Revert AbstractKotlinCodegen
alister995199 Aug 26, 2021
bafa9e8
Revert Codegen constants to remove base generator changes out of our …
alister995199 Aug 26, 2021
5603817
Revert data class template changes, add data class body check to Kotl…
Aug 26, 2021
1a60c02
Add sample generation yaml file for jvm-volley library
Aug 26, 2021
5e6db5f
Update JVM-Volley readme for generateRoomModels flag
Aug 26, 2021
ee1868e
Remove unused template files, get auth compiling but non functional, …
alister995199 Aug 27, 2021
daff15e
Merge branch 'master' of https://github.com/alisters/openapi-generator
alister995199 Aug 27, 2021
b5fe740
Generate sample generated code
Aug 27, 2021
0f8f685
Add not implemented method for oauth
alister995199 Aug 27, 2021
49993cc
Merge branch 'master' of https://github.com/alisters/openapi-generator
alister995199 Aug 27, 2021
d82caeb
Add unit test for KotlinClientCodegen generateRoomModel flag
Aug 27, 2021
274dba0
Merge branch 'master' of https://github.com/alisters/openapi-generator
Aug 27, 2021
9c4268e
Remove accidental hard coding of src/main/java source folder
alister995199 Aug 27, 2021
cf14378
Merge branch 'master' of https://github.com/alisters/openapi-generator
alister995199 Aug 27, 2021
e67403a
Push changed generated sample files
alister995199 Aug 31, 2021
3b76cde
Move and rename IStorable inside the volley library
alister995199 Sep 1, 2021
c9b3ef9
Inject retry policy into API definition, re-run sample and doc scripts
Sep 2, 2021
540b0a7
Add generic post processors
alister995199 Sep 7, 2021
1b47c9d
Update samples after generator changes
Sep 7, 2021
9b451c8
Fix some compile errors with the pet store sample
Sep 15, 2021
8f1e9b8
Fix duplicate auth companion object and import generation
alister995199 Sep 15, 2021
9f05c7a
Reinstate query and form parameter code generation
alister995199 Sep 15, 2021
b97193a
Merge branch 'master' of https://github.com/alisters/openapi-generator
Sep 16, 2021
4ae08fd
Add check for unsupported serialization libraries
Sep 16, 2021
609103f
Fix broken unit tests
Sep 16, 2021
02fa246
Regenerate samples
Sep 16, 2021
94bc961
AN-233 Update request factory to allow custom gsonadapters
australianfrog123 Sep 24, 2021
6f550c1
update `GsonRequest.mustache` and `RequestFactoy.mustache` to use `Ma…
TheY2T Sep 29, 2021
0d2c2f1
Update readme with better examples and design notes
alister995199 Oct 5, 2021
db6805c
Merge branch 'master' of https://github.com/alisters/openapi-generator
alister995199 Oct 5, 2021
5f75e39
Update readme with info about gson serializers and adapters for polym…
alister995199 Oct 5, 2021
4358e2b
Merge branch 'OpenAPITools:master' into master
alisters Oct 5, 2021
fbb5248
Updated samples
TheY2T Oct 5, 2021
59a82dc
Merge branch 'master' of https://github.com/alisters/openapi-generator
TheY2T Oct 5, 2021
62449bc
Merge from upstream
alister995199 Dec 7, 2021
7a8c982
Merge from upstream
alister995199 Dec 7, 2021
637ed4c
Address review comments
alister995199 Dec 9, 2021
90fd818
Update samples
Dec 9, 2021
3b95ce6
Samples
Dec 10, 2021
40c3870
Update docs
Dec 10, 2021
b587d5e
Remove DateAdapter generated file, template and it's inclusion as a s…
alister995199 Dec 13, 2021
d9eba2f
Merge branch 'master' of https://github.com/alisters/openapi-generator
alister995199 Dec 13, 2021
ad5c485
Review comment cleanup for initial PR #10253 - cleaner auth key in pa…
alister995199 Dec 13, 2021
8232b86
Review comment - add a kotlin version parameter to the build scripts
alister995199 Dec 14, 2021
5594087
Updated samples
Dec 14, 2021
edfe7a1
Missing changes from build.mustache
alister995199 Dec 14, 2021
835b1ca
Merge branch 'master' of https://github.com/alisters/openapi-generator
alister995199 Dec 14, 2021
44fa4e0
Regenerate samples for build.gradle changes
alister995199 Dec 14, 2021
1510afe
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
alister995199 Dec 14, 2021
abbfcf6
Merge from master and generate samples
alister995199 Dec 14, 2021
d05a42b
Remove serializer as a supporting file from jvm-volley - it's seriali…
alister995199 Dec 16, 2021
226ef91
Remove singleton serializer from jvm-volley generation as it's not used
alister995199 Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/configs/kotlin-jvm-volley.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
generatorName: kotlin
outputDir: samples/client/petstore/kotlin-jvm-volley
library: jvm-volley
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
additionalProperties:
artifactId: kotlin-petstore-jvm-volley
generateRoomModels: "true"
serializationLibrary: "gson"
3 changes: 2 additions & 1 deletion docs/generators/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|collectionType|Option. Collection type to use|<dl><dt>**array**</dt><dd>kotlin.Array</dd><dt>**list**</dt><dd>kotlin.collections.List</dd></dl>|list|
|dateLibrary|Option. Date library to use|<dl><dt>**threetenbp-localdatetime**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, for legacy app only)</dd><dt>**string**</dt><dd>String</dd><dt>**java8-localdatetime**</dt><dd>Java 8 native JSR310 (jvm only, for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (jvm only, preferred for jdk 1.8+)</dd><dt>**threetenbp**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, preferred for jdk &lt; 1.8)</dd></dl>|java8|
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |camelCase|
|generateRoomModels|Generate Android Room database models in addition to API models (JVM Volley library only)| |false|
|groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools|
|library|Library template (sub-template) to use|<dl><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-okhttp3**</dt><dd>Platform: Java Virtual Machine. HTTP client: OkHttp 3.12.4 (Android 2.3+ and Java 7+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-retrofit2**</dt><dd>Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.6.0. JSON processing: Kotlinx Serialization: 1.2.1.</dd></dl>|jvm-okhttp4|
|library|Library template (sub-template) to use|<dl><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-okhttp3**</dt><dd>Platform: Java Virtual Machine. HTTP client: OkHttp 3.12.4 (Android 2.3+ and Java 7+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-retrofit2**</dt><dd>Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.6.0. JSON processing: Kotlinx Serialization: 1.2.1.</dd><dt>**jvm-volley**</dt><dd>Platform: JVM for Android. HTTP client: Volley 1.2.1. JSON processing: gson 2.8.9</dd></dl>|jvm-okhttp4|
|modelMutable|Create mutable models| |false|
|moshiCodeGen|Whether to enable codegen with the Moshi library. Refer to the [official Moshi doc](https://github.com/square/moshi#codegen) for more info.| |false|
|omitGradlePluginVersions|Whether to declare Gradle plugin versions in build files.| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
protected static final String JVM_OKHTTP3 = "jvm-okhttp3";
protected static final String JVM_RETROFIT2 = "jvm-retrofit2";
protected static final String MULTIPLATFORM = "multiplatform";
protected static final String JVM_VOLLEY = "jvm-volley";

public static final String USE_RX_JAVA = "useRxJava";
public static final String USE_RX_JAVA2 = "useRxJava2";
public static final String USE_RX_JAVA3 = "useRxJava3";
public static final String USE_COROUTINES = "useCoroutines";
public static final String DO_NOT_USE_RX_AND_COROUTINES = "doNotUseRxAndCoroutines";
public static final String GENERATE_ROOM_MODELS = "generateRoomModels";
public static final String ROOM_MODEL_PACKAGE = "roomModelPackage";
public static final String OMIT_GRADLE_PLUGIN_VERSIONS = "omitGradlePluginVersions";

public static final String DATE_LIBRARY = "dateLibrary";
Expand All @@ -71,6 +74,9 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
// backwards compatibility for openapi configs that specify neither rx1 nor rx2
// (mustache does not allow for boolean operators so we need this extra field)
protected boolean doNotUseRxAndCoroutines = true;
protected boolean generateRoomModels = false;
protected String roomModelPackage = "";


protected String authFolder;

Expand Down Expand Up @@ -153,6 +159,9 @@ public KotlinClientCodegen() {

outputFolder = "generated-code" + File.separator + "kotlin-client";
modelTemplateFiles.put("model.mustache", ".kt");
if (generateRoomModels) {
modelTemplateFiles.put("model_room.mustache", ".kt");
}
apiTemplateFiles.put("api.mustache", ".kt");
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");
Expand Down Expand Up @@ -183,6 +192,7 @@ public KotlinClientCodegen() {
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.");
supportedLibraries.put(JVM_RETROFIT2, "Platform: Java Virtual Machine. HTTP client: Retrofit 2.6.2.");
supportedLibraries.put(MULTIPLATFORM, "Platform: Kotlin multiplatform. HTTP client: Ktor 1.6.0. JSON processing: Kotlinx Serialization: 1.2.1.");
supportedLibraries.put(JVM_VOLLEY, "Platform: JVM for Android. HTTP client: Volley 1.2.1. JSON processing: gson 2.8.9");

CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "Library template (sub-template) to use");
libraryOption.setEnum(supportedLibraries);
Expand All @@ -206,6 +216,8 @@ public KotlinClientCodegen() {

cliOptions.add(CliOption.newBoolean(MOSHI_CODE_GEN, "Whether to enable codegen with the Moshi library. Refer to the [official Moshi doc](https://github.com/square/moshi#codegen) for more info."));

cliOptions.add(CliOption.newBoolean(GENERATE_ROOM_MODELS, "Generate Android Room database models in addition to API models (JVM Volley library only)", false));

cliOptions.add(CliOption.newBoolean(SUPPORT_ANDROID_API_LEVEL_25_AND_BELLOW, "[WARNING] This flag will generate code that has a known security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in oder to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284"));
}

Expand All @@ -221,6 +233,12 @@ public String getHelp() {
return "Generates a Kotlin client.";
}

public boolean getGenerateRoomModels() { return generateRoomModels; }

public void setGenerateRoomModels(Boolean generateRoomModels) {
this.generateRoomModels = generateRoomModels;
}

public void setUseRxJava(boolean useRxJava) {
if (useRxJava) {
this.useRxJava2 = false;
Expand Down Expand Up @@ -284,14 +302,45 @@ public void setCollectionType(String collectionType) {
this.collectionType = collectionType;
}

public void setRoomModelPackage(String roomModelPackage) {
this.roomModelPackage = roomModelPackage;
}

@Override
public void processOpts() {
super.processOpts();
public String modelFilename(String templateName, String modelName) {
String suffix = modelTemplateFiles().get(templateName);
// If this was a proper template method, i wouldn't have to make myself throw up by doing this....
if (getGenerateRoomModels() && suffix.startsWith("RoomModel")) {
return roomModelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
} else {
return modelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
}
}

public String roomModelFileFolder() {
return outputFolder + File.separator + sourceFolder + File.separator + roomModelPackage.replace('.', File.separatorChar);
}

if (MULTIPLATFORM.equals(getLibrary())) {
sourceFolder = "src/commonMain/kotlin";
@Override
public void processOpts() {
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
} else {
// Set the value to defaults if we haven't overridden
if (MULTIPLATFORM.equals(getLibrary())) {
setSourceFolder("src/commonMain/kotlin");
}
else if (JVM_VOLLEY.equals(getLibrary())){
// Android plugin wants it's source in java
setSourceFolder("src/main/java");
}
else {
setSourceFolder(super.sourceFolder);
}
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, this.sourceFolder);
}

super.processOpts();

boolean hasRx = additionalProperties.containsKey(USE_RX_JAVA);
boolean hasRx2 = additionalProperties.containsKey(USE_RX_JAVA2);
Expand Down Expand Up @@ -334,6 +383,12 @@ public void processOpts() {
final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", "/");
authFolder = (sourceFolder + File.separator + packageName + File.separator + "auth").replace(".", "/");

// request destination folder
final String requestFolder = (sourceFolder + File.separator + packageName + File.separator + "request").replace(".", "/");

// auth destination folder
final String authFolder = (sourceFolder + File.separator + packageName + File.separator + "auth").replace(".", "/");

// additional properties
if (additionalProperties.containsKey(DATE_LIBRARY)) {
setDateLibrary(additionalProperties.get(DATE_LIBRARY).toString());
Expand All @@ -350,6 +405,9 @@ public void processOpts() {
case JVM_OKHTTP4:
processJVMOkHttpLibrary(infrastructureFolder);
break;
case JVM_VOLLEY:
processJVMVolleyLibrary(infrastructureFolder, requestFolder, authFolder);
break;
case JVM_RETROFIT2:
processJVMRetrofit2Library(infrastructureFolder);
break;
Expand Down Expand Up @@ -463,6 +521,45 @@ private void processJVMRetrofit2Library(String infrastructureFolder) {
addSupportingSerializerAdapters(infrastructureFolder);
}

private void processJVMVolleyLibrary(String infrastructureFolder, String requestFolder, String authFolder) {

additionalProperties.put(JVM, true);
additionalProperties.put(JVM_VOLLEY, true);

if (additionalProperties.containsKey(GENERATE_ROOM_MODELS)) {
this.setGenerateRoomModels(convertPropertyToBooleanAndWriteBack(GENERATE_ROOM_MODELS));
// Hide this option behind a property getter and setter in case we need to check it elsewhere
if (getGenerateRoomModels()) {
modelTemplateFiles.put("model_room.mustache", "RoomModel.kt");
supportingFiles.add(new SupportingFile("infrastructure/ITransformForStorage.mustache", infrastructureFolder, "ITransformForStorage.kt"));

}
} else {
additionalProperties.put(GENERATE_ROOM_MODELS, generateRoomModels);
}

if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
if (!additionalProperties.containsKey(ROOM_MODEL_PACKAGE))
this.setRoomModelPackage(packageName + ".models.room");
else
this.setRoomModelPackage(additionalProperties.get(ROOM_MODEL_PACKAGE).toString());
}
additionalProperties.put(ROOM_MODEL_PACKAGE, roomModelPackage);

supportingFiles.add(new SupportingFile("infrastructure/CollectionFormats.kt.mustache", infrastructureFolder, "CollectionFormats.kt"));

// We have auth related partial files, so they can be overridden, but don't generate them explicitly
supportingFiles.add(new SupportingFile("request/GsonRequest.mustache", requestFolder, "GsonRequest.kt"));
supportingFiles.add(new SupportingFile("request/IRequestFactory.mustache", requestFolder, "IRequestFactory.kt"));
supportingFiles.add(new SupportingFile("request/RequestFactory.mustache", requestFolder, "RequestFactory.kt"));
supportingFiles.add(new SupportingFile("infrastructure/CollectionFormats.kt.mustache", infrastructureFolder, "CollectionFormats.kt"));

if (getSerializationLibrary() != SERIALIZATION_LIBRARY_TYPE.gson) {
throw new RuntimeException("This library currently only supports gson serialization. Try adding '--additional-properties serializationLibrary=gson' to your command.");
}
addSupportingSerializerAdapters(infrastructureFolder);
}

private void addSupportingSerializerAdapters(final String infrastructureFolder) {
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/Serializer.kt.mustache", infrastructureFolder, "Serializer.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/ByteArrayAdapter.kt.mustache", infrastructureFolder, "ByteArrayAdapter.kt"));
Expand All @@ -479,7 +576,6 @@ private void addSupportingSerializerAdapters(final String infrastructureFolder)
break;

case gson:
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/DateAdapter.kt.mustache", infrastructureFolder, "DateAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateAdapter.kt.mustache", infrastructureFolder, "LocalDateAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/LocalDateTimeAdapter.kt.mustache", infrastructureFolder, "LocalDateTimeAdapter.kt"));
supportingFiles.add(new SupportingFile("jvm-common/infrastructure/OffsetDateTimeAdapter.kt.mustache", infrastructureFolder, "OffsetDateTimeAdapter.kt"));
Expand Down Expand Up @@ -594,6 +690,11 @@ private void commonSupportingFiles() {
if (getLibrary().equals(MULTIPLATFORM)) {
supportingFiles.add(new SupportingFile("build.gradle.kts.mustache", "", "build.gradle.kts"));
supportingFiles.add(new SupportingFile("settings.gradle.kts.mustache", "", "settings.gradle.kts"));
} else if (getLibrary().equals(JVM_VOLLEY)) {
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
supportingFiles.add(new SupportingFile("manifest.mustache", "", "src/main/AndroidManifest.xml"));
Comment on lines +708 to +711
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alisters just wondering, how different are those grade files from the other shared gradle files?
If they are very different, we should keep them separated, if they are similar, we should consider merge them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build.mustache/build.gradle is very different on account of android versus straight jvm/java builds.
Same goes for the manifest - Android only.
Other builds don't have a gradle properties - i could fold that into the build.gradle i think. Pretty new to gradle so i think myself or colleague Steve just made one by default - no strong rationale there.
The settings.gradle is the shared one - just keeping the conditional logic a bit cleaner there i guess ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

} else {
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
Expand All @@ -614,6 +715,9 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
for (Object model : models) {
@SuppressWarnings("unchecked") Map<String, Object> mo = (Map<String, Object>) model;
CodegenModel cm = (CodegenModel) mo.get("model");
if (getGenerateRoomModels()) {
cm.vendorExtensions.put("x-has-data-class-body", true);
}

// escape the variable base name for use as a string literal
List<CodegenProperty> vars = Stream.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import kotlinx.serialization.encoding.*
{{#serializableModel}}
import java.io.Serializable
{{/serializableModel}}
{{#generateRoomModels}}
import {{roomModelPackage}}.{{classname}}RoomModel
import {{packageName}}.infrastructure.ITransformForStorage
{{/generateRoomModels}}

/**
* {{{description}}}
Expand All @@ -56,8 +60,16 @@ import java.io.Serializable
{{#required}}{{>data_class_req_var}}{{/required}}{{^required}}{{>data_class_opt_var}}{{/required}}{{^-last}},{{/-last}}

{{/allVars}}
){{/discriminator}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{^serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{^parcelizeModels}} : Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{#parcelizeModels}} : Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#vendorExtensions.x-has-data-class-body}} {
){{/discriminator}}{{#parent}}{{^serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{^parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{^serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#parent}}{{#serializableModel}}{{#parcelizeModels}} : {{{parent}}}{{#isMap}}(){{/isMap}}{{#isArray}}(){{/isArray}}, Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{^parcelizeModels}} : Serializable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{^parent}}{{#serializableModel}}{{#parcelizeModels}} : Serializable, Parcelable{{/parcelizeModels}}{{/serializableModel}}{{/parent}}{{#generateRoomModels}}{{#parent}}, {{/parent}}{{^discriminator}}{{^parent}}:{{/parent}} ITransformForStorage<{{classname}}RoomModel>{{/discriminator}}{{/generateRoomModels}}{{#vendorExtensions.x-has-data-class-body}} {
{{/vendorExtensions.x-has-data-class-body}}
{{#generateRoomModels}}
companion object { }
{{^discriminator}}override fun toRoomModel(): {{classname}}RoomModel =
{{classname}}RoomModel(roomTableId = 0,
{{#allVars}}{{#items.isPrimitiveType}}{{#isArray}}{{#isList}}{{name}} = this.{{name}},{{/isList}}{{/isArray}}{{/items.isPrimitiveType}}{{^isEnum}}{{^isArray}}{{name}} = this.{{name}},{{/isArray}}{{/isEnum}}{{#isEnum}}{{^isArray}}{{name}} = this.{{name}},{{/isArray}}{{/isEnum}}
{{/allVars}}
){{/discriminator}}
{{/generateRoomModels}}
{{#serializableModel}}
{{#nonPublicApi}}internal {{/nonPublicApi}}companion object {
private const val serialVersionUID: Long = 123
Expand Down
Loading