more flattening fixes

This commit is contained in:
Tony Tam
2015-10-19 23:10:48 -07:00
parent 555fd54fbb
commit aaf1df1971
2 changed files with 52 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
package io.swagger.codegen;
import com.sun.org.apache.xpath.internal.operations.Mod;
import io.swagger.models.*;
import io.swagger.models.parameters.BodyParameter;
import io.swagger.models.parameters.Parameter;
@@ -43,14 +44,18 @@ public class InlineModelResolver {
BodyParameter bp = (BodyParameter) parameter;
if (bp.getSchema() != null) {
Model model = bp.getSchema();
String existing = matchGenerated(model);
if (existing != null) {
bp.setSchema(new RefModel(existing));
} else {
String name = uniqueName(bp.getName());
bp.setSchema(new RefModel(name));
addGenerated(name, model);
swagger.addDefinition(name, model);
if(model instanceof ModelImpl) {
ModelImpl obj = (ModelImpl) model;
flattenProperties(obj.getProperties(), pathname);
}
else if (model instanceof ArrayModel) {
ArrayModel am = (ArrayModel) model;
Property inner = am.getItems();
if(inner instanceof ObjectProperty) {
ObjectProperty op = (ObjectProperty) inner;
flattenProperties(op.getProperties(), pathname);
}
}
}
}
@@ -170,6 +175,7 @@ public class InlineModelResolver {
public String uniqueName(String key) {
int count = 0;
boolean done = false;
key = key.replaceAll("[^a-z_\\.A-Z0-9 ]", "");
while (!done) {
String name = key;
if (count > 0) {