Skip to content

Commit

Permalink
Annotate with @JsonClass classes with no parameters/variables
Browse files Browse the repository at this point in the history
  • Loading branch information
macisamuele committed Feb 3, 2020
1 parent bb15a09 commit 24eae7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,13 @@ open class KotlinGenerator : SharedCodegen() {
@VisibleForTesting
internal fun addRequiredImports(codegenModel: CodegenModel) {
// 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) {
if (codegenModel.allVars.isNotEmpty() || codegenModel.isEnum) {
codegenModel.imports.add("com.squareup.moshi.Json")
}

if (!codegenModel.isAlias) {
// If we are rendering a model (or enum) we are annotating it with @JsonClass,
// so we need to make sure that we're importing it
codegenModel.imports.add("com.squareup.moshi.JsonClass")
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/src/main/resources/kotlin/data_class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @property {{{name}}} {{description}}
{{/vars}}
*/
{{#hasVars}}@JsonClass(generateAdapter = true)
data {{/hasVars}}class {{classname}} {{#hasVars}}(
@JsonClass(generateAdapter = true)
{{#hasVars}}data {{/hasVars}}class {{classname}} {{#hasVars}}(
{{#requiredVars}}
{{>data_class_req_var}}{{^-last}},
{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
Expand Down

0 comments on commit 24eae7b

Please sign in to comment.