예제 #1
0
 @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;
 }
 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;
 }
  @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;
  }