コード例 #1
0
 private String formPath(String path, List<CodegenParameter> formParams) {
   String names = "Form";
   for (CodegenParameter p : formParams) {
     if (p.dataType.equals("FilePath")) {
       // file data processing
     }
     names += p.baseName;
   }
   if (formParams.size() > 0) {
     path += " :> ReqBody '[FormUrlEncoded] " + names;
   }
   return path;
 }
コード例 #2
0
  private static CodegenModel reconcileInlineEnums(
      CodegenModel codegenModel, CodegenModel parentCodegenModel) {
    // This generator uses inline classes to define enums, which breaks when
    // dealing with models that have subTypes. To clean this up, we will analyze
    // the parent and child models, look for enums that match, and remove
    // them from the child models and leave them in the parent.
    // Because the child models extend the parents, the enums will be available via the parent.

    // Only bother with reconciliation if the parent model has enums.
    if (parentCodegenModel.hasEnums) {

      // Get the properties for the parent and child models
      final List<CodegenProperty> parentModelCodegenProperties = parentCodegenModel.vars;
      List<CodegenProperty> codegenProperties = codegenModel.vars;

      // Iterate over all of the parent model properties
      boolean removedChildEnum = false;
      for (CodegenProperty parentModelCodegenPropery : parentModelCodegenProperties) {
        // Look for enums
        if (parentModelCodegenPropery.isEnum) {
          // Now that we have found an enum in the parent class,
          // and search the child class for the same enum.
          Iterator<CodegenProperty> iterator = codegenProperties.iterator();
          while (iterator.hasNext()) {
            CodegenProperty codegenProperty = iterator.next();
            if (codegenProperty.isEnum && codegenProperty.equals(parentModelCodegenPropery)) {
              // We found an enum in the child class that is
              // a duplicate of the one in the parent, so remove it.
              iterator.remove();
              removedChildEnum = true;
            }
          }
        }
      }

      if (removedChildEnum) {
        // If we removed an entry from this model's vars, we need to ensure hasMore is updated
        int count = 0, numVars = codegenProperties.size();
        for (CodegenProperty codegenProperty : codegenProperties) {
          count += 1;
          codegenProperty.hasMore = (count < numVars) ? true : null;
        }
        codegenModel.vars = codegenProperties;
      }
    }

    return codegenModel;
  }
コード例 #3
0
 private String findCommonPrefixOfVars(List<String> vars) {
   String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
   // exclude trailing characters that should be part of a valid variable
   // e.g. ["status-on", "status-off"] => "status-" (not "status-o")
   return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
 }