Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[Feature Request] Extending protovalidate-java to other JVM Protobuf implementations

未關閉
#80 0 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@pkwarren 已經在處理了。

開始於 2023年12月27日。

評估

這個 Issue 還沒有評估資料。

描述

Feature

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.

主要語言
Java
星號
70
分支
17
平均合併
2 天 13 小時
30 天內合併 PR
13

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

bufbuild/protovalidate-java 的其他 Issue

查看 bufbuild/protovalidate-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。