Skip to content

Commit

Permalink
don't configure the parent with allOf
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Jun 3, 2016
1 parent 43e649e commit be6f068
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ public Model allOfModel(ObjectNode node, String location, ParseResult result) {
}
} else if (allOf != null) {
ComposedModel model = null;
// we only support one parent, no multiple inheritance or composition
if(allOf.getNodeType().equals(JsonNodeType.ARRAY)) {
model = new ComposedModel();

Expand All @@ -831,28 +830,22 @@ public Model allOfModel(ObjectNode node, String location, ParseResult result) {
pos++;
}

List<Model> allComponents = model.getAllOf();
int size = allComponents.size();
if (size >= 1) {
// Parent is the first composed component, by definition.
model.setParent(allComponents.get(0));
Model child = null;
if (size >= 2) {
List<RefModel> interfaces = new ArrayList<RefModel>();
for (Model m : allComponents.subList(1, size/* - 1*/)) {
if (m instanceof RefModel) {
interfaces.add((RefModel) m);
} else if (m instanceof ModelImpl) {
// NOTE: since ComposedModel.child allows only one inline child schema, the last one 'wins'.
child = m;
}
}
model.setInterfaces(interfaces);
}
if(child != null) {
model.setChild(child);
Model child = null;
List<RefModel> interfaces = new ArrayList<RefModel>();
for (Model m : model.getAllOf()) {
if (m instanceof RefModel) {
interfaces.add((RefModel) m);
} else if (m instanceof ModelImpl) {
// NOTE: since ComposedModel.child allows only one inline child schema, the last one 'wins'.
child = m;
}
}
model.setInterfaces(interfaces);

if(child != null) {
model.setChild(child);
}

}
else {
result.invalidType(location, "allOf", "array", allOf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,9 @@ private Swagger doRelativeFileTest(String location) {
final RefProperty reflexMapAdditionalProperties = (RefProperty) reflexMap.getAdditionalProperties();
assertEquals(reflexMapAdditionalProperties.get$ref(), "#/definitions/reflex");

final RefModel parent = (RefModel) composedCat.getParent();
assertEquals(parent.get$ref(), "#/definitions/pet");

assertEquals(composedCat.getInterfaces().size(), 1);
assertEquals(composedCat.getInterfaces().get(0).get$ref(), "#/definitions/foo");
assertEquals(composedCat.getInterfaces().size(), 2);
assertEquals(composedCat.getInterfaces().get(0).get$ref(), "#/definitions/pet");
assertEquals(composedCat.getInterfaces().get(1).get$ref(), "#/definitions/foo");

return swagger;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,14 +988,13 @@ public void testIssue204_allOf() throws Exception {
assertNotNull("Dog model not found", dog);
assertTrue("Dog model is not composed", dog instanceof ComposedModel);
ComposedModel dogComposed = (ComposedModel) dog;
assertTrue("Dog does not have a parent", dogComposed.getParent() instanceof RefModel);
RefModel dogParentRef = (RefModel) dogComposed.getParent();
Model dogParent = definitions.get(dogParentRef.getSimpleRef());
assertEquals("Dog does not extend Pet", pet, dogParent);
assertNotNull("Dog does not implement any interfaces", dogComposed.getInterfaces());
assertEquals("Dog implements the wrong number of interfaces;", 1, dogComposed.getInterfaces().size());
assertEquals("Dog implements the wrong number of interfaces;", 2, dogComposed.getInterfaces().size());
RefModel dogInterfaceRef = dogComposed.getInterfaces().get(0);
Model dogInterface = definitions.get(dogInterfaceRef.getSimpleRef());
assertEquals("Dog does not implement Pet;", pet, dogInterface);
dogInterfaceRef = dogComposed.getInterfaces().get(1);
dogInterface = definitions.get(dogInterfaceRef.getSimpleRef());
assertEquals("Dog does not implement Furry;", furry, dogInterface);
assertTrue("Dog does not have child properties", dogComposed.getChild() instanceof ModelImpl);
}
Expand Down

0 comments on commit be6f068

Please sign in to comment.