From ed8e474fed21dc4b4cd4f1b351a2f9287cbc9a26 Mon Sep 17 00:00:00 2001 From: Chris Roche Date: Thu, 9 Jul 2026 10:42:43 -0400 Subject: [PATCH] Fix Duration doc examples to use message literal syntax The const, lt, lte, in, and not_in examples in DurationRules showed string values like "5s", which do not compile for google.protobuf.Duration option fields. Replace them with message literal syntax matching the gt, gte, and example docs. Fixes #499 --- proto/protovalidate/buf/validate/validate.proto | 14 +++++++++----- tools/internal/gen/buf/validate/validate.pb.go | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/proto/protovalidate/buf/validate/validate.proto b/proto/protovalidate/buf/validate/validate.proto index 56117c88..9fe0f8d4 100644 --- a/proto/protovalidate/buf/validate/validate.proto +++ b/proto/protovalidate/buf/validate/validate.proto @@ -4458,7 +4458,7 @@ message DurationRules { // ```proto // message MyDuration { // // value must equal 5s - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.const = "5s"]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration.const = { seconds: 5 }]; // } // ``` optional google.protobuf.Duration const = 2 [(predefined).cel = { @@ -4473,7 +4473,7 @@ message DurationRules { // ```proto // message MyDuration { // // must be less than 5s - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = "5s"]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = { seconds: 5 }]; // } // ``` google.protobuf.Duration lt = 3 [(predefined).cel = { @@ -4490,7 +4490,7 @@ message DurationRules { // ```proto // message MyDuration { // // must be less than or equal to 10s - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lte = "10s"]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lte = { seconds: 10 }]; // } // ``` google.protobuf.Duration lte = 4 [(predefined).cel = { @@ -4611,7 +4611,9 @@ message DurationRules { // ```proto // message MyDuration { // // must be in list [1s, 2s, 3s] - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.in = ["1s", "2s", "3s"]]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration = { + // in: [{ seconds: 1 }, { seconds: 2 }, { seconds: 3 }] + // }]; // } // ``` repeated google.protobuf.Duration in = 7 [(predefined).cel = { @@ -4627,7 +4629,9 @@ message DurationRules { // ```proto // message MyDuration { // // value must not be in list [1s, 2s, 3s] - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.not_in = ["1s", "2s", "3s"]]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration = { + // not_in: [{ seconds: 1 }, { seconds: 2 }, { seconds: 3 }] + // }]; // } // ``` repeated google.protobuf.Duration not_in = 8 [(predefined).cel = { diff --git a/tools/internal/gen/buf/validate/validate.pb.go b/tools/internal/gen/buf/validate/validate.pb.go index 2ee537a3..1518c851 100644 --- a/tools/internal/gen/buf/validate/validate.pb.go +++ b/tools/internal/gen/buf/validate/validate.pb.go @@ -6591,7 +6591,7 @@ type DurationRules struct { // // message MyDuration { // // value must equal 5s - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.const = "5s"]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration.const = { seconds: 5 }]; // } // // ``` @@ -6614,7 +6614,9 @@ type DurationRules struct { // // message MyDuration { // // must be in list [1s, 2s, 3s] - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.in = ["1s", "2s", "3s"]]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration = { + // in: [{ seconds: 1 }, { seconds: 2 }, { seconds: 3 }] + // }]; // } // // ``` @@ -6628,7 +6630,9 @@ type DurationRules struct { // // message MyDuration { // // value must not be in list [1s, 2s, 3s] - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.not_in = ["1s", "2s", "3s"]]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration = { + // not_in: [{ seconds: 1 }, { seconds: 2 }, { seconds: 3 }] + // }]; // } // // ``` @@ -6774,7 +6778,7 @@ type DurationRules_Lt struct { // // message MyDuration { // // must be less than 5s - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = "5s"]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = { seconds: 5 }]; // } // // ``` @@ -6790,7 +6794,7 @@ type DurationRules_Lte struct { // // message MyDuration { // // must be less than or equal to 10s - // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lte = "10s"]; + // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lte = { seconds: 10 }]; // } // // ```