String typeName = entry.getKey();
TypeRef typeRef = entry.getValue();
Type type = typeRef.type;
ClassDoc typeClassDoc = type.asClassDoc();
OptionalName propertyTypeFormat = this.translator.typeName(type);
String propertyType = propertyTypeFormat.value();
// set enum values
List<String> allowableValues = ParserHelper.getAllowableValues(typeClassDoc);
if (allowableValues != null) {
propertyType = "string";
}
Type containerOf = ParserHelper.getContainerType(type, this.varsToTypes);
String itemsRef = null;
String itemsType = null;
String containerTypeOf = containerOf == null ? null : this.translator.typeName(containerOf).value();
if (containerOf != null) {
if (ParserHelper.isPrimitive(containerOf, this.options)) {
itemsType = containerTypeOf;
} else {
itemsRef = containerTypeOf;
}
}
Boolean uniqueItems = null;
if (propertyType.equals("array")) {
if (ParserHelper.isSet(type.qualifiedTypeName())) {
uniqueItems = Boolean.TRUE;
}
}
String validationContext = " for the " + typeRef.sourceDesc + " of the class: " + classDoc.name();
// validate min/max
ParserHelper.verifyNumericValue(validationContext + " min value.", propertyTypeFormat.value(), propertyTypeFormat.getFormat(), typeRef.min);
ParserHelper.verifyNumericValue(validationContext + " max value.", propertyTypeFormat.value(), propertyTypeFormat.getFormat(), typeRef.max);
// if enum and default value check it matches the enum values
if (allowableValues != null && typeRef.defaultValue != null && !allowableValues.contains(typeRef.defaultValue)) {
throw new IllegalStateException(" Invalid value for the default value of the " + typeRef.sourceDesc + " it should be one of: "
+ allowableValues);
}
// verify default vs min, max and by itself
if (typeRef.defaultValue != null) {
if (typeRef.min == null && typeRef.max == null) {
// just validate the default
ParserHelper.verifyValue(validationContext + " default value.", propertyTypeFormat.value(), propertyTypeFormat.getFormat(),
typeRef.defaultValue);
}
// if min/max then default is validated as part of comparison
if (typeRef.min != null) {
int comparison = ParserHelper.compareNumericValues(validationContext + " min value.", propertyTypeFormat.value(),
propertyTypeFormat.getFormat(), typeRef.defaultValue, typeRef.min);
if (comparison < 0) {
throw new IllegalStateException("Invalid value for the default value of the " + typeRef.sourceDesc + " it should be >= the minimum: "
+ typeRef.min);
}
}
if (typeRef.max != null) {
int comparison = ParserHelper.compareNumericValues(validationContext + " max value.", propertyTypeFormat.value(),
propertyTypeFormat.getFormat(), typeRef.defaultValue, typeRef.max);
if (comparison > 0) {
throw new IllegalStateException("Invalid value for the default value of the " + typeRef.sourceDesc + " it should be <= the maximum: "
+ typeRef.max);
}
}
}
Property property = new Property(typeRef.rawName, typeRef.paramCategory, propertyType, propertyTypeFormat.getFormat(), typeRef.description,
itemsRef, itemsType, uniqueItems, allowableValues, typeRef.min, typeRef.max, typeRef.defaultValue);
elements.put(typeName, property);
}
return elements;
}