Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

1.0 update usage question

Đang mở
#362 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tài liệu
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
java, kotlin
Lĩnh vực
api, developer-experience

Hướng nghiên cứu

Bắt đầu với ví dụ GuestAddressTest trong issue và xem xét thiết lập ValidatorFactory cùng các trường violation mà nó kiểm tra. Xác định và ghi lại cách sử dụng được hỗ trợ trong 1.0 để kiểm tra chi tiết constraint và trường, bao gồm các thuộc tính nullable và các đường dẫn descriptor; ví dụ phải thể hiện rõ các assertions dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bufbuild/protovalidate-java

Tất cả issue của bufbuild/protovalidate-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.