-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix issue #2449: SubClass annotations are missing from the base class. #2467
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,19 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) { | |
} | ||
} | ||
} | ||
// Let parent know about all its children | ||
for (String name : allModels.keySet()) { | ||
CodegenModel cm = allModels.get(name); | ||
if (cm.parent == null) continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
CodegenModel parent = allModels.get(cm.parent); | ||
if (parent.children == null) { | ||
parent.children = new ArrayList<CodegenModel>(); | ||
} else { | ||
parent.children.get(parent.children.size() - 1).hasMoreChildren = Boolean.TRUE; | ||
} | ||
parent.children.add(cm); | ||
parent.hasChildren = true; | ||
} | ||
} | ||
return objs; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { | |
|
||
public JavaClientCodegen() { | ||
super(); | ||
supportsInheritance = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cannot be done at the moment. See : #1120 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, I have a PR on the swagger-parser that would make supportsInheritance work : swagger-api/swagger-parser#246 |
||
outputFolder = "generated-code" + File.separator + "java"; | ||
modelTemplateFiles.put("model.mustache", ".java"); | ||
apiTemplateFiles.put("api.mustache", ".java"); | ||
|
@@ -238,6 +239,8 @@ public void processOpts() { | |
importMapping.put("ApiModelProperty", "io.swagger.annotations.ApiModelProperty"); | ||
importMapping.put("ApiModel", "io.swagger.annotations.ApiModel"); | ||
importMapping.put("JsonProperty", "com.fasterxml.jackson.annotation.JsonProperty"); | ||
importMapping.put("JsonSubTypes", "com.fasterxml.jackson.annotation.JsonSubTypes"); | ||
importMapping.put("JsonTypeInfo", "com.fasterxml.jackson.annotation.JsonTypeInfo"); | ||
importMapping.put("JsonValue", "com.fasterxml.jackson.annotation.JsonValue"); | ||
importMapping.put("Objects", "java.util.Objects"); | ||
importMapping.put("StringUtil", invokerPackage + ".StringUtil"); | ||
|
@@ -542,6 +545,10 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe | |
if(codegenModel.description != null) { | ||
codegenModel.imports.add("ApiModel"); | ||
} | ||
if (codegenModel.discriminator != null) { | ||
codegenModel.imports.add("JsonSubTypes"); | ||
codegenModel.imports.add("JsonTypeInfo"); | ||
} | ||
if (allDefinitions != null && codegenModel != null && codegenModel.parentSchema != null && codegenModel.hasEnums) { | ||
final Model parentModel = allDefinitions.get(codegenModel.parentSchema); | ||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}" ) | ||
@JsonSubTypes({ | ||
{{#children}}@JsonSubTypes.Type(value = {{name}}.class, name = "{{name}}"){{#hasMoreChildren}}, | ||
{{/hasMoreChildren}}{{/children}} | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (CodegenModel cm : allModels.values())
?