Skip to content

Commit

Permalink
Merge pull request #8476 from john-french/refLastInAllOf
Browse files Browse the repository at this point in the history
Fix for $ref as last element in allOf error
  • Loading branch information
frantuma committed Jul 25, 2018
2 parents 9082126 + 4faf281 commit 9ede7b0
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 9ede7b0

Please sign in to comment.