Skip to content

Commit

Permalink
do not assume anything when it comes to allOf!
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy authored and John French committed Jul 24, 2018
1 parent 9082126 commit 4faf281
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
allRequired = null;
}
// parent model
RefModel parent = (RefModel) composed.getParent();
Model parent = (Model) composed.getParent();

// interfaces (intermediate models)
if (composed.getInterfaces() != null) {
Expand Down Expand Up @@ -1416,16 +1416,31 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
}

if (parent != null) {
final String parentRef = parent.getSimpleRef();
m.parentSchema = parentRef;
m.parent = toModelName(parent.getSimpleRef());
addImport(m, m.parent);
if (allDefinitions != null) {
final Model parentModel = allDefinitions.get(m.parentSchema);
if (supportsInheritance) {
addProperties(allProperties, allRequired, parentModel, allDefinitions);
} else {
addProperties(properties, required, parentModel, allDefinitions);
String parentName = null;
if(parent instanceof RefModel) {
parentName = ((RefModel)parent).getSimpleRef();
}
else {
if(parent instanceof ModelImpl) {
// check for a title
ModelImpl parentImpl = (ModelImpl) parent;
if(StringUtils.isNotBlank(parentImpl.getTitle())) {
parentName = parentImpl.getTitle();
}
}
}

if(parentName != null) {
m.parentSchema = parentName;
m.parent = toModelName(parentName);
addImport(m, m.parent);
if (allDefinitions != null) {
final Model parentModel = allDefinitions.get(m.parentSchema);
if (supportsInheritance) {
addProperties(allProperties, allRequired, parentModel, allDefinitions);
} else {
addProperties(properties, required, parentModel, allDefinitions);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ private Model getParent(Model model) {
models.putAll(config.additionalProperties());
allProcessedModels.put(name, models);
} catch (Exception e) {
throw new RuntimeException("Could not process model '" + name + "'" + ".Please make sure that your schema is correct!", e);
String message = "Could not process model '" + name + "'" + ". Please make sure that your schema is correct!";
LOGGER.error(message, e);
throw new RuntimeException(message, e);
}
}

Expand Down

0 comments on commit 4faf281

Please sign in to comment.