@SuppressWarnings("static-method") public Map<String, Object> processOperations( CodegenConfig config, String tag, List<CodegenOperation> ops) { Map<String, Object> operations = new HashMap<String, Object>(); Map<String, Object> objs = new HashMap<String, Object>(); objs.put("classname", config.toApiName(tag)); objs.put("pathPrefix", config.toApiVarName(tag)); // check for operationId uniqueness Set<String> opIds = new HashSet<String>(); int counter = 0; for (CodegenOperation op : ops) { String opId = op.nickname; if (opIds.contains(opId)) { counter++; op.nickname += "_" + counter; } opIds.add(opId); } objs.put("operation", ops); operations.put("operations", objs); operations.put("package", config.apiPackage()); Set<String> allImports = new LinkedHashSet<String>(); for (CodegenOperation op : ops) { allImports.addAll(op.imports); } List<Map<String, String>> imports = new ArrayList<Map<String, String>>(); for (String nextImport : allImports) { Map<String, String> im = new LinkedHashMap<String, String>(); String mapping = config.importMapping().get(nextImport); if (mapping == null) { mapping = config.toModelImport(nextImport); } if (mapping != null) { im.put("import", mapping); imports.add(im); } } operations.put("imports", imports); // add a flag to indicate whether there's any {{import}} if (imports.size() > 0) { operations.put("hasImport", true); } config.postProcessOperations(operations); if (objs.size() > 0) { List<CodegenOperation> os = (List<CodegenOperation>) objs.get("operation"); if (os != null && os.size() > 0) { CodegenOperation op = os.get(os.size() - 1); op.hasMore = null; } } return operations; }
@SuppressWarnings("static-method") public Map<String, Object> processModels( CodegenConfig config, Map<String, Model> definitions, Map<String, Model> allDefinitions) { Map<String, Object> objs = new HashMap<String, Object>(); objs.put("package", config.modelPackage()); List<Object> models = new ArrayList<Object>(); Set<String> allImports = new LinkedHashSet<String>(); for (String key : definitions.keySet()) { Model mm = definitions.get(key); CodegenModel cm = config.fromModel(key, mm, allDefinitions); Map<String, Object> mo = new HashMap<String, Object>(); mo.put("model", cm); mo.put("importPath", config.toModelImport(key)); models.add(mo); allImports.addAll(cm.imports); } objs.put("models", models); Set<String> importSet = new TreeSet<String>(); for (String nextImport : allImports) { String mapping = config.importMapping().get(nextImport); if (mapping == null) { mapping = config.toModelImport(nextImport); } if (mapping != null && !config.defaultIncludes().contains(mapping)) { importSet.add(mapping); } // add instantiation types mapping = config.instantiationTypes().get(nextImport); if (mapping != null && !config.defaultIncludes().contains(mapping)) { importSet.add(mapping); } } List<Map<String, String>> imports = new ArrayList<Map<String, String>>(); for (String s : importSet) { Map<String, String> item = new HashMap<String, String>(); item.put("import", s); imports.add(item); } objs.put("imports", imports); config.postProcessModels(objs); return objs; }