[Feature Request] Extending protovalidate-java to other JVM Protobuf implementations
@pkwarren đang làm issue này rồi.
Từ ngày 27/12/2023.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Feature description:
I'd like to generify the Value interface to accommodate validation of Protobuf messages generated by other implementations. Specifically I'd like to implement support for protokt.
Problem it solves or use case:
It would be nice to write another implementation of protovalidate for a JVM language without having to reinvent the wheel or fork this project.
Proposed implementation or solution:
It turns out you don't have to do much to generify this project.
First you change Value to reference a generic "MessageLike" interface. Then from everything that fails to compile, I derived the exact reflection capabilities protovalidate-java requires of a Protobuf runtime:
// This name is subject to change.
interface MessageLike {
// Whether a message has a field. This can be a standard field or a member of a oneof.
boolean hasField(FieldDescriptor field);
// Get the value of a field. This can be a standard field or a member of a oneof.
Value getField(FieldDescriptor field);
}
Separately the Value interface changes slightly. Sometimes we need to extract the JVM value to verify things in Java code (e.g. Any type URL or enum value); sometimes we need the binding value that the runtime under test should provide to CEL's runtime.
Contribution:
I have already implemented this proposal[1]. My fork passes all conformance tests for protobuf-java and protokt[2]. The branch is a bit sloppy since it's a POC, but the conformance tests can be swapped from the Java implementation to the protokt implementation by changing the main class of the conformance:conformance task from Main to Main2.
https://github.com/andrewparmet/protovalidate-protokt/pull/9
If my changes to the various evaluator classes can be merged here, then I can write a spinoff library that reuses the majority of the implementation code in this project to validate Protokt messages.
As a bonus it would be great to be able to generate the conformance test cases using the protobuf-gradle-plugin from a JAR on Maven Central so I don't have to invoke buf export. Maybe protovalidate-java can bundle them. Protokt manually syncs its conformance proto file with the main protobuf repo so buf export is still better on the whole.
Thanks!
[1] The implementation requires a few changes to protokt found on this branch. merged
[2] With a small set of tests that I think are not actually always possible to cover given a proto3-compliant runtime. These are called out in my branch, but I force them to pass anyways since there's no option to skip them like the Protobuf conformance tests and I didn't want to figure out how to make a failure list for the hack into the existing protovalidate-java conformance runtime. fixed
Additional context:
I'm the author of protokt and the buf-gradle-plugin.
- Ngôn ngữ chính
- Java
- Star
- 70
- Fork
- 17
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 13
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bufbuild/protovalidate-java
-
Bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
bufbuild/protovalidate-java#379 · 4 bình luận · 1 reaction ·
-
1.0 update usage question Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
bufbuild/protovalidate-java#362 · 1 bình luận ·
Tất cả issue của bufbuild/protovalidate-java
Issue tương tự
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Đang mởarea/plugin
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
kestra-io/plugin-kestra#190 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Add canonical URLs and a sitemap Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
apache/rocketmq-dashboard#5064 ·