protected fun verify
(propertyName
: String, otype
: OType, readOnly
: Boolean, nullable
: Boolean) {
val signature = "$propertyName:$otype:$readOnly:$nullable";
val verified = verifiedProperties[kclass];
if (verified?.contains(signature) == true)
return;
val properties = allowedProperties[kclass] ?: throw RuntimeAPIConstraintError("No properties registered for this class.", kclass);
val property = properties.firstOrNull { it.a == propertyName } ?: throw SchemaMismatchException(propertyName, "No such property exists for this class.");
if (property != Tuple5(propertyName, otype, null, readOnly, nullable)) {
if (otype != property.b)
throw SchemaMismatchException("$propertyName.otype", "${property.b}", "$otype", "Property type does not match.");
if (property.c != null)
throw SchemaMismatchException("$propertyName.linked", "${property.c}", "null", "The property must be of linked/embedded type.");
if (readOnly != property.d)
throw SchemaMismatchException("$propertyName.readOnly", "${property.d}", "$readOnly", "The property should ${readOnly .. "not" ?: ""} be read-only.");
if (nullable != property.e)
throw SchemaMismatchException("$propertyName.nullable", "${property.e}", "$nullable", "The property ${nullable .. "cannot" ?: "must"} be nullable.");
}
if (verified == null)
verifiedProperties[kclass] = mutableListOf(signature);
else
verified += signature;
}
val signature = "$propertyName:$otype:${ linkedClass.toLowerCase() }:$readOnly:$nullable";
val verified = verifiedProperties[kclass];
if (verified?.contains(signature) == true)
return;
val properties = allowedProperties[kclass] ?: throw RuntimeAPIConstraintError("No properties registered for this class.", kclass);
val property = properties.firstOrNull { it.a == propertyName } ?: throw SchemaMismatchException(propertyName, "No such property exists for this class.");
val thisProp = Tuple5(propertyName, otype, linkedClass.toLowerCase().right(), readOnly, nullable);
if (property != thisProp && property.copy(c = "_".right()) != thisProp) {
if (otype != property.b)
throw SchemaMismatchException("$propertyName.otype", "${property.b}", "$otype", "Property type does not match.");
property.c.also {
if (it == null)
throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of linked type.");
else
when (it) {
is Either.Left ->
throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of linked type.");
is Either.Right ->
if (it.b != linkedClass)
throw SchemaMismatchException("$propertyName.linkedClass", it.b, linkedClass, "The property should be of a different linked class.");
}
}
if (readOnly != property.d)
throw SchemaMismatchException("$propertyName.readOnly", "${property.d}", "$readOnly", "The property should ${readOnly .. "not" ?: ""} be read-only.");
if (nullable != property.e)
throw SchemaMismatchException("$propertyName.nullable", "${property.e}", "$nullable", "The property ${nullable .. "cannot" ?: "must"} be nullable.");
}
if (verified == null)
verifiedProperties[kclass] = mutableListOf(signature);
else
verified += signature;
}
protected fun verify
(propertyName
: String, otype
: OType, linkedType
: OType, readOnly
: Boolean, nullable
: Boolean) {
val signature = "$propertyName:$otype:$linkedType:$readOnly:$nullable";
val verified = verifiedProperties[kclass];
if (verified?.contains(signature) == true)
return;
val properties = allowedProperties[kclass] ?: throw RuntimeAPIConstraintError("No properties registered for this class.", kclass);
val property = properties.firstOrNull { it.a == propertyName } ?: throw SchemaMismatchException(propertyName, "No such property exists for this class.");
if (property != Tuple5(propertyName, otype, linkedType.left(), readOnly, nullable)) {
if (otype != property.b)
throw SchemaMismatchException("$propertyName.otype", "${property.b}", "$otype", "Property type does not match.");
property.c.also {
if (it == null)
throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of embedded type.");
else when (it) {
is Either.Right ->
throw SchemaMismatchException(propertyName, "$it", "null", "The property should be of embedded type.");
is Either.Left ->
if (it.a != linkedType)
throw SchemaMismatchException("$propertyName.linkedType", "${it.a}", "$linkedType", "The property should be of a different embedded type.");
}
}
if (readOnly != property.d)
throw SchemaMismatchException("$propertyName.readOnly", "${property.d}", "$readOnly", "The property should ${readOnly .. "not" ?: ""} be read-only.");
if (nullable != property.e)
throw SchemaMismatchException("$propertyName.nullable", "${property.e}", "$nullable", "The property ${nullable .. "cannot" ?: "must"} be nullable.");
}
if (verified == null)
verifiedProperties[kclass] = mutableListOf(signature);
else
verified += signature;
}