コード例 #1
0
ファイル: Generation.java プロジェクト: nickshen3/isis
 static StringProperty stringPropertyEnum(String... enumValues) {
   StringProperty stringProperty = stringProperty();
   stringProperty._enum(Arrays.asList(enumValues));
   if (enumValues.length >= 1) {
     stringProperty._default(enumValues[0]);
   }
   return stringProperty;
 }
コード例 #2
0
  private Model asModel(String typeName, Swagger swagger) {
    boolean array = typeName.endsWith("[]");
    if (array) {
      typeName = typeName.substring(0, typeName.length() - 2);
    }

    if (swagger.getDefinitions() != null) {
      for (Model model : swagger.getDefinitions().values()) {
        StringProperty modelType = (StringProperty) model.getVendorExtensions().get("x-className");
        if (modelType != null && typeName.equals(modelType.getFormat())) {
          return model;
        }
      }
    }
    return null;
  }
コード例 #3
0
  /**
   * Return the default value of the property
   *
   * @param p Swagger property object
   * @return string presentation of the default value of the property
   */
  @Override
  public String toDefaultValue(Property p) {
    if (p instanceof StringProperty) {
      StringProperty dp = (StringProperty) p;
      if (dp.getDefault() != null) {
        return "'" + dp.getDefault().toString() + "'";
      }
    } else if (p instanceof BooleanProperty) {
      BooleanProperty dp = (BooleanProperty) p;
      if (dp.getDefault() != null) {
        if (dp.getDefault().toString().equalsIgnoreCase("false")) return "False";
        else return "True";
      }
    } else if (p instanceof DateProperty) {
      // TODO
    } else if (p instanceof DateTimeProperty) {
      // TODO
    } else if (p instanceof DoubleProperty) {
      DoubleProperty dp = (DoubleProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    } else if (p instanceof FloatProperty) {
      FloatProperty dp = (FloatProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    } else if (p instanceof IntegerProperty) {
      IntegerProperty dp = (IntegerProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    } else if (p instanceof LongProperty) {
      LongProperty dp = (LongProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    }

    return null;
  }
コード例 #4
0
  @Override
  public String toDefaultValue(Property p) {
    if (p instanceof IntegerProperty) {
      IntegerProperty dp = (IntegerProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    } else if (p instanceof LongProperty) {
      LongProperty dp = (LongProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    } else if (p instanceof DoubleProperty) {
      DoubleProperty dp = (DoubleProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    } else if (p instanceof FloatProperty) {
      FloatProperty dp = (FloatProperty) p;
      if (dp.getDefault() != null) {
        return dp.getDefault().toString();
      }
    } else if (p instanceof BooleanProperty) {
      BooleanProperty bp = (BooleanProperty) p;
      if (bp.getDefault() != null) {
        return bp.getDefault().toString();
      }
    } else if (p instanceof StringProperty) {
      StringProperty sp = (StringProperty) p;
      if (sp.getDefault() != null) {
        return "\"" + escapeText(sp.getDefault()) + "\"";
      }
    }

    return null;
  }
コード例 #5
0
 @Override
 public String toDefaultValue(Property p) {
   if (p instanceof ArrayProperty) {
     final ArrayProperty ap = (ArrayProperty) p;
     final String pattern;
     if (fullJavaUtil) {
       pattern = "new java.util.ArrayList<%s>()";
     } else {
       pattern = "new ArrayList<%s>()";
     }
     return String.format(pattern, getTypeDeclaration(ap.getItems()));
   } else if (p instanceof MapProperty) {
     final MapProperty ap = (MapProperty) p;
     final String pattern;
     if (fullJavaUtil) {
       pattern = "new java.util.HashMap<String, %s>()";
     } else {
       pattern = "new HashMap<String, %s>()";
     }
     return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()));
   } else if (p instanceof IntegerProperty) {
     IntegerProperty dp = (IntegerProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString();
     }
     return "null";
   } else if (p instanceof LongProperty) {
     LongProperty dp = (LongProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString() + "l";
     }
     return "null";
   } else if (p instanceof DoubleProperty) {
     DoubleProperty dp = (DoubleProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString() + "d";
     }
     return "null";
   } else if (p instanceof FloatProperty) {
     FloatProperty dp = (FloatProperty) p;
     if (dp.getDefault() != null) {
       return dp.getDefault().toString() + "f";
     }
     return "null";
   } else if (p instanceof BooleanProperty) {
     BooleanProperty bp = (BooleanProperty) p;
     if (bp.getDefault() != null) {
       return bp.getDefault().toString();
     }
     return "null";
   } else if (p instanceof StringProperty) {
     StringProperty sp = (StringProperty) p;
     if (sp.getDefault() != null) {
       String _default = sp.getDefault();
       if (sp.getEnum() == null) {
         return "\"" + escapeText(_default) + "\"";
       } else {
         // convert to enum var name later in postProcessModels
         return _default;
       }
     }
     return "null";
   }
   return super.toDefaultValue(p);
 }