/** * Returns the property value as {@link Integer} or return the default value if null. */ public Integer getInteger(String key,Integer defaultValue){ Integer i = get(key); return null == i ? defaultValue : i; }
public MApiPropertyBuilder readProperty(String name, Map<String,Object> map, SwaggerExtension ex) { MApiPropertyBuilder mp = new MApiPropertyBuilder(); JsonObject p = JsonObject.of(map); readParameterBase(name, p, mp, ex); mp.setName(name); //yaml read all values to string. mp.setIdentity(p.getBoolean(X_IDENTITY, false)); mp.setUnique(p.getBoolean(X_UNIQUE, false)); mp.setSortable(p.get(X_SORTABLE, Boolean.class)); mp.setFilterable(p.get(X_FILTERABLE, Boolean.class)); mp.setCreatable(p.get(X_CREATABLE, Boolean.class)); mp.setUpdatable(p.get(X_UPDATABLE, Boolean.class)); mp.setExpandable(p.get(X_EXPANDABLE, Boolean.class)); return mp; }
protected void readParameterBase(String name, JsonObject p, MApiParameterBaseBuilder mp, SwaggerExtension ex) { mp.setName(p.getString(NAME)); mp.setTitle(p.getString(TITLE)); mp.setSummary(p.getString(SUMMARY)); mp.setDescription(p.getString(DESCRIPTION)); mp.setRequired(p.get(REQUIRED, Boolean.class)); mp.setType(readParameterType(name, p, ex)); mp.setDefaultValue(p.get(DEFAULT)); MApiValidationBuilder v = new MApiValidationBuilder(); v.setPattern(p.getString(PATTERN)); v.setMaxLength(p.getInteger(MAX_LENGTH)); v.setMinLength(p.getInteger(MIN_LENGTH)); v.setMaximum(p.get(MAXIMUM)); v.setExclusiveMaximum(p.getBoolean(EXCLUSIVE_MAXIMUM, v.isExclusiveMaximum())); v.setMinimum(p.get(MINIMUM)); v.setExclusiveMinimum(p.getBoolean(EXCLUSIVE_MINIMUM, v.isExclusiveMinimum())); List<String> enumValues = p.getList(ENUM); if(null != enumValues) { mp.setEnumValues(enumValues.toArray(Arrays2.EMPTY_STRING_ARRAY)); } mp.setValidation(v); readFormat(p, mp); }
/** * Returns the property value as {@link Long}. */ public Long getLong(String key){ return get(key); }
/** * Returns the property value as {@link Float} or returns the default value if null. */ public Float getFloat(String key,Float defaultValue){ Float f = get(key); return null == f ? defaultValue : f; }
/** * Returns the property value as {@link Map}. */ public Map<String,Object> getMap(String key){ return (Map<String,Object>)get(key); }
/** * Returns the property value as {@link Boolean}. */ public Boolean getBoolean(String key){ return get(key); }
/** * Returns the property value as {@link Boolean} or return the default value if null. */ public Boolean getBoolean(String key,Boolean defaultValue){ Boolean b = get(key); return null == b ? defaultValue : b; }
/** * Returns the property value as {@link Double} or returns the default value if null. */ public Double getDouble(String key,Double defaultValue){ Double d = get(key); return null == d ? defaultValue : d; }
/** * Returns the property value as {@link Float}. */ public Float getFloat(String key){ return get(key); }
/** * Returns the property value as {@link List}. */ public <T> List<T> getList(String key) { return (List<T>)get(key); }
/** * Returns the property value as {@link Integer}. */ public Integer getInteger(String key){ return get(key); }
/** * Returns the property value as {@link Long} or return the default value if null. */ public Long getLong(String key,Long defaultValue){ Long l = get(key); return null == l ? defaultValue : l; }
/** * Returns the property value as {@link Double}. */ public Double getDouble(String key){ return get(key); }
/** * Process all the properties of the object property in this json object. */ public void getObject(String key, BiConsumer<String,Object> func) { Map<String,Object> map = get(key); if(null != map) { for(Map.Entry<String,Object> entry : map.entrySet()) { func.accept(entry.getKey(), entry.getValue()); } } }
/** * Wraps the property value as {@link JsonValue}. */ public JsonValue getValue(String key){ Object o = get(key); return null == o ? null : JsonValue.of(o); }
/** * Wraps the property value as {@link JsonObject}. */ public JsonObject getObject(String key){ Map map = get(key); return null == map ? null : new JsonObject(map); }
/** * Wraps the property value as {@link JsonArray}. */ public JsonArray getArray(String key){ List list = get(key); return null == list ? null : new JsonArray(list); }
@Override public void parseJson(JsonValue json) { if(json.isObject()) { JsonObject o = json.asJsonObject(); this.user = toRule(o.get("user")); this.client = toRule(o.get("client")); return; } Object v = json.raw(); if(v instanceof String) { this.parseString((String)v); return; } throw new IllegalStateException("Can't parse json value '" + v + "'"); }
protected MProperty readComplexTypeProperty(String name, Map<String,Object> map) { MPropertyBuilder mp = new MPropertyBuilder(); JsonObject p = JsonObject.of(map); mp.setName(name); mp.setRequired(p.get(REQUIRED, Boolean.class)); mp.setType(readType(p)); return mp.build(); }