@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;
  }
Exemplo n.º 2
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;
 }
  @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;
  }