@Override
  public void addOperationToGroup(
      String tag,
      String resourcePath,
      Operation operation,
      CodegenOperation co,
      Map<String, List<CodegenOperation>> operations) {
    String basePath = resourcePath;
    if (basePath.startsWith("/")) {
      basePath = basePath.substring(1);
    }
    int pos = basePath.indexOf("/");
    if (pos > 0) {
      basePath = basePath.substring(0, pos);
    }

    if (basePath == "") {
      basePath = "default";
    } else {
      if (co.path.startsWith("/" + basePath)) {
        co.path = co.path.substring(("/" + basePath).length());
      }
      co.subresourceOperation = !co.path.isEmpty();
    }
    List<CodegenOperation> opList = operations.get(basePath);
    if (opList == null) {
      opList = new ArrayList<CodegenOperation>();
      operations.put(basePath, opList);
    }
    opList.add(co);
    co.baseName = basePath;
  }
 @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.summary = operation.getSummary();
   op.notes = operation.getDescription();
   return op;
 }
  @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;
  }
 @Override
 public CodegenOperation fromOperation(
     String resourcePath,
     String httpMethod,
     Operation operation,
     Map<String, Model> definitions,
     Swagger swagger) {
   CodegenOperation op =
       super.fromOperation(resourcePath, httpMethod, operation, definitions, swagger);
   String path = op.path;
   op.nickname =
       addReturnPath(
           headerPath(
               formPath(
                   bodyPath(
                       queryPath(
                           capturePath(replacePathSplitter(path), op.pathParams), op.queryParams),
                       op.bodyParams),
                   op.formParams),
               op.headerParams),
           op.httpMethod,
           op.returnType);
   return op;
 }
 public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
   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) {
       List<CodegenResponse> responses = operation.responses;
       if (responses != null) {
         for (CodegenResponse resp : responses) {
           if ("0".equals(resp.code)) {
             resp.code = "200";
           }
         }
       }
       if (operation.returnType == null) {
         operation.returnType = "Void";
       } else if (operation.returnType.startsWith("List")) {
         String rt = operation.returnType;
         int end = rt.lastIndexOf(">");
         if (end > 0) {
           operation.returnType = rt.substring("List<".length(), end).trim();
           operation.returnContainer = "List";
         }
       } else if (operation.returnType.startsWith("Map")) {
         String rt = operation.returnType;
         int end = rt.lastIndexOf(">");
         if (end > 0) {
           operation.returnType = rt.substring("Map<".length(), end).split(",")[1].trim();
           operation.returnContainer = "Map";
         }
       } else if (operation.returnType.startsWith("Set")) {
         String rt = operation.returnType;
         int end = rt.lastIndexOf(">");
         if (end > 0) {
           operation.returnType = rt.substring("Set<".length(), end).trim();
           operation.returnContainer = "Set";
         }
       }
     }
   }
   return objs;
 }