diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d0a6402e3..3f3310bc0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ protobuf-java = "4.29.1" protobuf-js = "7.4.0" protobufGradlePlugin = "0.9.4" protovalidate = "0.9.0" -protovalidateJava = "0.4.2" +protovalidateJava = "0.5.0" slf4j = "2.0.16" # build diff --git a/protokt-protovalidate/src/main/kotlin/protokt/v1/buf/validate/Validator.kt b/protokt-protovalidate/src/main/kotlin/protokt/v1/buf/validate/Validator.kt index 774939ea7..056abad1e 100644 --- a/protokt-protovalidate/src/main/kotlin/protokt/v1/buf/validate/Validator.kt +++ b/protokt-protovalidate/src/main/kotlin/protokt/v1/buf/validate/Validator.kt @@ -58,8 +58,15 @@ class Validator @JvmOverloads constructor( descriptor.nestedTypes.forEach(::doLoad) } - fun validate(message: Message): ValidationResult = - evaluatorsByFullTypeName + fun validate(message: Message): ValidationResult { + val result = evaluatorsByFullTypeName .getValue(message::class.findAnnotation()!!.fullTypeName) .evaluate(MessageValue(message.toDynamicMessage(runtimeContext)), failFast) + + return if (result.isEmpty()) { + ValidationResult.EMPTY + } else { + ValidationResult(result.map { it.build() }) + } + } } diff --git a/testing/protovalidate-conformance/src/main/kotlin/protokt/v1/buf/validate/conformance/Main.kt b/testing/protovalidate-conformance/src/main/kotlin/protokt/v1/buf/validate/conformance/Main.kt index 9665cfcc8..b613ad8a2 100644 --- a/testing/protovalidate-conformance/src/main/kotlin/protokt/v1/buf/validate/conformance/Main.kt +++ b/testing/protovalidate-conformance/src/main/kotlin/protokt/v1/buf/validate/conformance/Main.kt @@ -94,7 +94,11 @@ object Main { TestResult.newBuilder().setSuccess(true).build() } else { TestResult.newBuilder() - .setValidationError(Violations.newBuilder().addAllViolations(result.violations).build()) + .setValidationError( + Violations.newBuilder() + .addAllViolations(result.toProto().violationsList) + .build() + ) .build() } } catch (e: ExecutionException) {