
com.simiacryptus.openai.proxy.ValidatedObject.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of joe-penai Show documentation
Show all versions of joe-penai Show documentation
A Java client for OpenAI's API
The newest version!
package com.simiacryptus.openai.proxy
import kotlin.reflect.full.memberProperties
interface ValidatedObject {
fun validate(): Boolean = validateFields(this)
companion object {
fun validateFields(obj: Any): Boolean {
obj.javaClass.declaredFields.forEach { field ->
field.isAccessible = true
val value = field.get(obj)
if (value is ValidatedObject && !value.validate()) {
return false
}
// If the property is a list, validate each element
if (value is List<*>) {
value.forEach {
if (it is ValidatedObject && !it.validate()) {
return false
}
}
}
}
obj.javaClass.kotlin.memberProperties.forEach { property ->
val value = property.getter.call(obj)
if (value is ValidatedObject && !value.validate()) {
return false
}
// If the property is a list, validate each element
if (value is List<*>) {
value.forEach {
if (it is ValidatedObject && !it.validate()) {
return false
}
}
}
}
return true
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy