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

1.0 update usage question

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

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
25/100
Issue 類型
文件
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
java, kotlin

研究方向

從 issue 中的 GuestAddressTest 範例開始,檢視 ValidatorFactory 的設定以及它所演示的 violation 欄位。判定並記錄 1.0 支援的、用於檢查 constraint 與欄位詳細資訊的用法,包括 nullable 屬性和 descriptor 路徑;範例應清楚地展示預期的 assertions。

由索引模型根據 Issue 內容生成。

描述

I'm updating to the 1.0 version of protovalidate-java, and there's a breaking change in how I consume the violations that I'm confused by.

Given this sample message:

message GuesAAddress {
  optional string zip_code = 1 [
    (buf.validate.field).required = true,
    (buf.validate.field).string.len = 5
  ];
}

I guessed at the changes I needed to make to unit test this.

 package common.guest.v1
 
-import build.buf.protovalidate.Validator
+import build.buf.protovalidate.ValidatorFactory
@@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test
 
 class GuestAddressTest {
 
-    private val validator = Validator()
+    private val validator = ValidatorFactory.newBuilder().build()
 
     @Test
     fun `validate guest address - field wrong length`() {
@@ -24,8 +24,8 @@ class GuestAddressTest {
 
         result.violations.size shouldBe 1
         assertSoftly(result.violations[0]) {
-            constraintId shouldBe "string.len"
-            fieldPath shouldBe "zip_code"
+            fieldValue?.descriptor?.fullName shouldBe "common.guest.v1.GuestAddress.zip_code"
+            ruleValue?.descriptor?.fullName shouldBe "buf.validate.StringRules.len"
         }
     }
 }

Is what I did the expected usage change, or is there a cleaner way to inspect the fields? Them being nullable felt odd, and the path to get to those fields was not obvious to me.

Appreciate it - thanks.

主要語言
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 摘要。