forked from loafle/openapi-generator-original
added models support per #291
This commit is contained in:
parent
ffda821f68
commit
48f8e16fb0
@ -7,9 +7,9 @@ import java.util.*;
|
||||
|
||||
public class CodegenModel {
|
||||
public String parent;
|
||||
public String name, classname, description;
|
||||
public String name, classname, description, classVarName, modelJson;
|
||||
public String defaultValue;
|
||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
|
||||
public Set<String> imports = new HashSet<String>();
|
||||
public Boolean hasVars, emptyVars;
|
||||
public Boolean hasVars, emptyVars, hasMoreModels;
|
||||
}
|
@ -316,6 +316,8 @@ public class DefaultCodegen {
|
||||
m.name = name;
|
||||
m.description = model.getDescription();
|
||||
m.classname = toModelName(name);
|
||||
m.classVarName = toVarName(name);
|
||||
m.modelJson = Json.pretty(model);
|
||||
int count = 0;
|
||||
if(model instanceof ArrayModel) {
|
||||
ArrayModel am = (ArrayModel) model;
|
||||
|
@ -34,21 +34,22 @@ public class DefaultGenerator implements Generator {
|
||||
}
|
||||
try {
|
||||
config.processOpts();
|
||||
Map<String, Object> models = null;
|
||||
// models = null;
|
||||
List<Object> allOperations = new ArrayList<Object>();
|
||||
|
||||
List<Object> allModels = new ArrayList<Object>();
|
||||
// models
|
||||
Map<String, Model> definitions = swagger.getDefinitions();
|
||||
for(String name: definitions.keySet()) {
|
||||
Model model = definitions.get(name);
|
||||
Map<String, Model> modelMap = new HashMap<String, Model>();
|
||||
modelMap.put(name, model);
|
||||
models = processModels(config, modelMap);
|
||||
Map<String, Object> models = processModels(config, modelMap);
|
||||
models.putAll(config.additionalProperties());
|
||||
|
||||
allModels.add(((List<Object>)models.get("models")).get(0));
|
||||
for(String templateName : config.modelTemplateFiles().keySet()) {
|
||||
String suffix = config.modelTemplateFiles().get(templateName);
|
||||
String filename = config.modelFileFolder() + File.separator + config.toModelFilename(name) + suffix;
|
||||
|
||||
String template = readTemplate(config.templateDir() + File.separator + templateName);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@ -58,7 +59,6 @@ public class DefaultGenerator implements Generator {
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
|
||||
writeToFile(filename, tmpl.execute(models));
|
||||
}
|
||||
}
|
||||
@ -101,6 +101,13 @@ public class DefaultGenerator implements Generator {
|
||||
Map<String, Object> apis = new HashMap<String, Object>();
|
||||
apis.put("apis", allOperations);
|
||||
bundle.put("apiInfo", apis);
|
||||
bundle.put("models", allModels);
|
||||
|
||||
for(int i = 0; i < allModels.size() - 1; i++) {
|
||||
HashMap<String, CodegenModel> cm = (HashMap<String, CodegenModel>) allModels.get(i);
|
||||
CodegenModel m = cm.get("model");
|
||||
m.hasMoreModels = true;
|
||||
}
|
||||
|
||||
for(SupportingFile support : config.supportingFiles()) {
|
||||
String outputFolder = config.outputFolder();
|
||||
|
Loading…
x
Reference in New Issue
Block a user