1.0 update usage question
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 25/100
- Issue 類型
- 文件
- 描述清晰度
- 需要釐清
- 活躍度
- 停滯
研究方向
從 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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
bufbuild/protovalidate-java 的其他 Issue
-
Bug
難度 3/5 1-2 天 新手友好度 45/100
bufbuild/protovalidate-java#379 · 4 則留言 · 1 個 reaction ·
-
Feature
bufbuild/protovalidate-java#80 · 已指派 1 人 ·
查看 bufbuild/protovalidate-java 的全部 Issue
相似的 Issue
-
area/plugin
難度 2/5 1-3 小時 新手友好度 75/100
kestra-io/plugin-kestra#190 ·
-
難度 2/5 1-3 小時 新手友好度 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
apache/rocketmq-dashboard#5064 ·