update response to support array of inline model

This commit is contained in:
wing328 2015-12-17 17:01:14 +08:00
parent c8a10aee33
commit 13b03d92d4

View File

@ -103,11 +103,23 @@ public class InlineModelResolver {
} }
} else if (property instanceof ArrayProperty) { } else if (property instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) property; ArrayProperty ap = (ArrayProperty) property;
if(ap.getItems() instanceof ObjectProperty) { Property inner = ap.getItems();
ObjectProperty op = (ObjectProperty) ap.getItems();
Map<String, Property> props = op.getProperties(); if(inner instanceof ObjectProperty) {
flattenProperties(props, "path"); String modelName = uniqueName("inline_response_" + key);
} ObjectProperty op = (ObjectProperty) inner;
flattenProperties(op.getProperties(), pathname);
Model inner_model = modelFromProperty(op, modelName);
String existing = matchGenerated(inner_model);
if (existing != null) {
ap.setItems(new RefProperty(existing));
} else {
ap.setItems(new RefProperty(modelName));
addGenerated(modelName, inner_model);
swagger.addDefinition(modelName, inner_model);
}
}
} else if (property instanceof MapProperty) { } else if (property instanceof MapProperty) {
MapProperty op = (MapProperty) property; MapProperty op = (MapProperty) property;
@ -367,4 +379,5 @@ public class InlineModelResolver {
public void setSkipMatches(boolean skipMatches) { public void setSkipMatches(boolean skipMatches) {
this.skipMatches = skipMatches; this.skipMatches = skipMatches;
} }
} }