Skip to content

Commit

Permalink
Merge pull request spring-io#997 from swagger-api/issue-966
Browse files Browse the repository at this point in the history
added jackson annotations on generated interface for deserialization
  • Loading branch information
HugoMario authored Dec 19, 2021
2 parents 137b149 + e3fbdfd commit d195575
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,17 @@ protected void addInterfaces(List<Schema> schemas, CodegenModel codegenModel, Ma
continue;
}
final String schemaName = ref.substring(ref.lastIndexOf("/") + 1);
this.addInterfaceModel(allModels.get(codegenConfig.toModelName(schemaName)), codegenModel);

final CodegenModel model = allModels.get(codegenConfig.toModelName(schemaName));
this.addInterfaceModel(model, codegenModel);

boolean subTypeAdded = false;
if (codegenModel.getSubTypes() != null) {
subTypeAdded = codegenModel.getSubTypes().stream().anyMatch(existingSubType -> existingSubType.classname.equalsIgnoreCase(model.classname));
}
if (!subTypeAdded) {
codegenModel.addSubType(model);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/handlebars/Java/interface.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{{#jackson}}
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
{{/jackson}}
/**
* {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
*/
{{#jackson}}
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
{{#subTypes}}
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{classname}}"){{^@last}},{{/@last}}
{{/subTypes}}
})
{{/jackson}}
public interface {{{classname}}} {
}

0 comments on commit d195575

Please sign in to comment.