From 4faf281f9e5db62d13860483a257ead256ae6fbd Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 21 Jun 2017 15:09:52 -0700 Subject: [PATCH] do not assume anything when it comes to `allOf`! --- .../io/swagger/codegen/DefaultCodegen.java | 37 +++++++++++++------ .../io/swagger/codegen/DefaultGenerator.java | 4 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 94485144346..d97ef392b01 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1383,7 +1383,7 @@ public CodegenModel fromModel(String name, Model model, Map allDe allRequired = null; } // parent model - RefModel parent = (RefModel) composed.getParent(); + Model parent = (Model) composed.getParent(); // interfaces (intermediate models) if (composed.getInterfaces() != null) { @@ -1416,16 +1416,31 @@ public CodegenModel fromModel(String name, Model model, Map 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); + } } } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index 738172cb80d..f10297e10f0 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -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); } }