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

Annotate with @JsonClass classes with no parameters/variables #88

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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) {
cortinico marked this conversation as resolved.
Show resolved Hide resolved
// 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

package com.yelp.codegen.generatecodesamples.models

import com.squareup.moshi.JsonClass

/**
*
*/
@JsonClass(generateAdapter = true)
class EmptyModel