Skip to content

Commit

Permalink
flatten composed property to fix generic type issue
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario committed Jul 10, 2020
1 parent 6ec8781 commit ee0e79e
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 ee0e79e

Please sign in to comment.