Skip to content

Commit

Permalink
Merge pull request #10377 from swagger-api/issue-9996
Browse files Browse the repository at this point in the history
flatten composed property to fix generic type issue
  • Loading branch information
HugoMario authored Jul 10, 2020
2 parents 6ec8781 + ee0e79e commit b9a731a
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,22 @@ public void flattenProperties(Map<String, Property> properties, String path) {
}
}
}
} else if (property instanceof ComposedProperty) {
ComposedProperty composedProperty = (ComposedProperty) property;
String modelName = resolveModelName(composedProperty.getTitle(), path + "_" + key);
Model model = modelFromProperty(composedProperty, modelName);
String existing = matchGenerated(model);
if (existing != null) {
RefProperty refProperty = new RefProperty(existing);
refProperty.setRequired(composedProperty.getRequired());
propsToUpdate.put(key, refProperty);
} else {
RefProperty refProperty = new RefProperty(modelName);
refProperty.setRequired(composedProperty.getRequired());
propsToUpdate.put(key, refProperty);
addGenerated(modelName, model);
swagger.addDefinition(modelName, model);
}
}
}
if (propsToUpdate.size() > 0) {
Expand Down Expand Up @@ -428,6 +444,30 @@ public Model modelFromProperty(ObjectProperty object, String path) {
return model;
}

public Model modelFromProperty(ComposedProperty composedProperty, String path) {
String description = composedProperty.getDescription();
String example = null;

Object obj = composedProperty.getExample();
if (obj != null) {
example = obj.toString();
}
Xml xml = composedProperty.getXml();

ModelImpl model = new ModelImpl();
model.type(composedProperty.getType());
model.setDescription(description);
model.setExample(example);
model.setName(path);
model.setXml(xml);
if (composedProperty.getVendorExtensions() != null) {
for (String key : composedProperty.getVendorExtensions().keySet()) {
model.setVendorExtension(key, composedProperty.getVendorExtensions().get(key));
}
}
return model;
}

@SuppressWarnings("static-method")
public Model modelFromProperty(MapProperty object, @SuppressWarnings("unused") String path) {
String description = object.getDescription();
Expand Down

0 comments on commit b9a731a

Please sign in to comment.