@Override public Map<String, Object> postProcessOperations(Map<String, Object> objs) { if ("retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary())) { Map<String, Object> operations = (Map<String, Object>) objs.get("operations"); if (operations != null) { List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation"); for (CodegenOperation operation : ops) { if (operation.hasConsumes == Boolean.TRUE) { Map<String, String> firstType = operation.consumes.get(0); if (firstType != null) { if ("multipart/form-data".equals(firstType.get("mediaType"))) { operation.isMultipart = Boolean.TRUE; } } } if (operation.returnType == null) { operation.returnType = "Void"; } if ("retrofit2".equals(getLibrary()) && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/")) operation.path = operation.path.substring(1); } } } return objs; }
@Override public CodegenOperation fromOperation( String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) { CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger); op.path = sanitizePath(op.path); return op; }
@Override public Map<String, Object> postProcessOperations(Map<String, Object> objs) { // Remove imports of List, ArrayList, Map and HashMap as they are // imported in the template already. List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports"); Pattern pattern = Pattern.compile("java\\.util\\.(List|ArrayList|Map|HashMap)"); for (Iterator<Map<String, String>> itr = imports.iterator(); itr.hasNext(); ) { String _import = itr.next().get("import"); if (pattern.matcher(_import).matches()) { itr.remove(); } } if (usesAnyRetrofitLibrary()) { Map<String, Object> operations = (Map<String, Object>) objs.get("operations"); if (operations != null) { List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation"); for (CodegenOperation operation : ops) { if (operation.hasConsumes == Boolean.TRUE) { Map<String, String> firstType = operation.consumes.get(0); if (firstType != null) { if ("multipart/form-data".equals(firstType.get("mediaType"))) { operation.isMultipart = Boolean.TRUE; } } } if (operation.returnType == null) { operation.returnType = "Void"; } if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/")) operation.path = operation.path.substring(1); } } } return objs; }