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

Add Support for moshi-codegen #68

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class KotlinGenerator : SharedCodegen() {
// If there are any vars, we will mark them with the @Json annotation so we have to make sure to import it
if (codegenModel.vars.isNotEmpty() || codegenModel.isEnum) {
codegenModel.imports.add("com.squareup.moshi.Json")
codegenModel.imports.add("com.squareup.moshi.JsonClass")
}

// Add import for @XNullable annotation if there are any XNullable properties
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/main/resources/kotlin/data_class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @property {{{name}}} {{description}}
{{/vars}}
*/
{{#hasVars}}@JsonClass(generateAdapter = true){{/hasVars}}
{{#hasVars}}data {{/hasVars}}class {{classname}} {{#hasVars}}(
{{#requiredVars}}
{{>data_class_req_var}}{{^-last}},
Expand All @@ -17,6 +18,7 @@
* {{{description}}}
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}
*/
@JsonClass(generateAdapter = false)
enum class {{enumName}}(val value: {{complexType}}){ {{#allowableValues}}{{#enumVars}}
@Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}}{{/-last}}{{/enumVars}}{{/allowableValues}}
}
Expand Down
1 change: 1 addition & 0 deletions plugin/src/main/resources/kotlin/enum_class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* {{{description}}}
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
*/
@JsonClass(generateAdapter = false)
enum class {{classname}}(val value: {{dataType}}){
{{#allowableValues}}{{#enumVars}} @Json(name = {{{value}}}) {{&name}}({{{value}}}){{^-last}},{{/-last}}
{{/enumVars}}{{/allowableValues}}}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package {{packageName}}.tools

import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Converter
import retrofit2.converter.moshi.MoshiConverterFactory


object GeneratedCodeConverters {
private val moshi = Moshi.Builder()
.add(XNullableAdapterFactory())
.add(KotlinJsonAdapterFactory())
.add(TypesAdapterFactory())
.build()

Expand Down
6 changes: 3 additions & 3 deletions samples/generated-code/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.41"

// Moshi + OkHttp + Retrofit
implementation "com.squareup.moshi:moshi:1.8.0"
implementation "com.squareup.moshi:moshi-adapters:1.8.0"
implementation "com.squareup.moshi:moshi-kotlin:1.8.0"
implementation "com.squareup.moshi:moshi:1.9.0"
implementation "com.squareup.moshi:moshi-adapters:1.9.0"
implementation "com.squareup.moshi:moshi-kotlin:1.9.0"
implementation "com.squareup.okhttp3:okhttp:3.12.3"
implementation "com.squareup.retrofit2:retrofit:2.6.0"
implementation "com.squareup.retrofit2:converter-moshi:2.6.0"
Expand Down
6 changes: 3 additions & 3 deletions samples/groovy-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.41"

// Moshi + OkHttp + Retrofit
implementation "com.squareup.moshi:moshi:1.8.0"
implementation "com.squareup.moshi:moshi-adapters:1.8.0"
implementation "com.squareup.moshi:moshi-kotlin:1.8.0"
implementation "com.squareup.moshi:moshi:1.9.0"
implementation "com.squareup.moshi:moshi-adapters:1.9.0"
implementation "com.squareup.moshi:moshi-kotlin:1.9.0"
implementation "com.squareup.okhttp3:okhttp:3.12.3"
implementation "com.squareup.retrofit2:retrofit:2.6.0"
implementation "com.squareup.retrofit2:converter-moshi:2.6.0"
Expand Down
6 changes: 3 additions & 3 deletions samples/junit-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.41"

// Moshi + OkHttp + Retrofit
implementation "com.squareup.moshi:moshi:1.8.0"
implementation "com.squareup.moshi:moshi-adapters:1.8.0"
implementation "com.squareup.moshi:moshi-kotlin:1.8.0"
implementation "com.squareup.moshi:moshi:1.9.0"
implementation "com.squareup.moshi:moshi-adapters:1.9.0"
implementation "com.squareup.moshi:moshi-kotlin:1.9.0"
implementation "com.squareup.okhttp3:okhttp:3.12.3"
implementation "com.squareup.retrofit2:retrofit:2.6.0"
implementation "com.squareup.retrofit2:converter-moshi:2.6.0"
Expand Down
6 changes: 3 additions & 3 deletions samples/kotlin-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.41")

// Moshi + OkHttp + Retrofit
implementation("com.squareup.moshi:moshi:1.8.0")
implementation("com.squareup.moshi:moshi-adapters:1.8.0")
implementation("com.squareup.moshi:moshi-kotlin:1.8.0")
implementation("com.squareup.moshi:moshi:1.9.0")
implementation("com.squareup.moshi:moshi-adapters:1.9.0")
implementation("com.squareup.moshi:moshi-kotlin:1.9.0")
implementation("com.squareup.okhttp3:okhttp:3.12.3")
implementation("com.squareup.retrofit2:retrofit:2.6.0")
implementation("com.squareup.retrofit2:converter-moshi:2.6.0")
Expand Down