Skip to content

Commit

Permalink
Allow to detect wellknown types in nested messages (#505)
Browse files Browse the repository at this point in the history
* detect wellknown types in nested messages

Signed-off-by: Bert Van Hauwaert <bert@becoded.be>

* revert Makefile

Signed-off-by: Bert Van Hauwaert <bert@becoded.be>

* Revert bumping resoruces / deps

Signed-off-by: Bert Van Hauwaert <bert@becoded.be>

* revert tests go.mod and validate version

Signed-off-by: Bert Van Hauwaert <bert@becoded.be>

* revert clean up unused

Signed-off-by: Bert Van Hauwaert <bert@becoded.be>
  • Loading branch information
becoded committed Aug 16, 2021
1 parent acd090f commit 338a2fb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion templates/shared/well_known.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ const (
)

func FileNeeds(f pgs.File, wk WellKnown) bool {
for _, msg := range f.Messages() {
for _, msg := range f.AllMessages() {
needed := Needs(msg, wk)
if needed {
return true
}
}

return false
}

Expand Down
2 changes: 2 additions & 0 deletions tests/harness/cases/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ proto_library(
"subdirectory/in_subdirectory.proto",
"wkt_any.proto",
"wkt_duration.proto",
"wkt_nested.proto",
"wkt_timestamp.proto",
"wkt_wrappers.proto",
],
Expand Down Expand Up @@ -97,6 +98,7 @@ py_proto_library(
"strings.proto",
"wkt_any.proto",
"wkt_duration.proto",
"wkt_nested.proto",
"wkt_timestamp.proto",
"wkt_wrappers.proto",
],
Expand Down
18 changes: 18 additions & 0 deletions tests/harness/cases/wkt_nested.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package tests.harness.cases;
option go_package = "github.com/envoyproxy/protoc-gen-validate/tests/harness/cases/go;cases";

import "validate/validate.proto";

message WktLevelOne {
message WktLevelTwo {
message WktLevelThree {
string uuid = 1 [(validate.rules).string.uuid = true];
}

WktLevelThree three = 1 [(validate.rules).message.required = true];
}

WktLevelTwo two = 1 [(validate.rules).message.required = true];
}
2 changes: 2 additions & 0 deletions tests/harness/cc/diamond_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "tests/harness/cases/wkt_any.pb.validate.h"
#include "tests/harness/cases/wkt_duration.pb.h"
#include "tests/harness/cases/wkt_duration.pb.validate.h"
#include "tests/harness/cases/wkt_nested.pb.h"
#include "tests/harness/cases/wkt_nested.pb.validate.h"
#include "tests/harness/cases/wkt_timestamp.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.validate.h"
2 changes: 2 additions & 0 deletions tests/harness/cc/diamond_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "tests/harness/cases/wkt_any.pb.validate.h"
#include "tests/harness/cases/wkt_duration.pb.h"
#include "tests/harness/cases/wkt_duration.pb.validate.h"
#include "tests/harness/cases/wkt_nested.pb.h"
#include "tests/harness/cases/wkt_nested.pb.validate.h"
#include "tests/harness/cases/wkt_timestamp.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.h"
#include "tests/harness/cases/wkt_wrappers.pb.validate.h"
Expand Down
2 changes: 2 additions & 0 deletions tests/harness/cc/harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "tests/harness/cases/wkt_any.pb.validate.h"
#include "tests/harness/cases/wkt_duration.pb.h"
#include "tests/harness/cases/wkt_duration.pb.validate.h"
#include "tests/harness/cases/wkt_nested.pb.h"
#include "tests/harness/cases/wkt_nested.pb.validate.h"
#include "tests/harness/cases/wkt_timestamp.pb.h"
#include "tests/harness/cases/wkt_timestamp.pb.validate.h"
#include "tests/harness/cases/wkt_wrappers.pb.h"
Expand Down
6 changes: 6 additions & 0 deletions tests/harness/executor/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func init() {
timestampCases,
anyCases,
kitchenSink,
nestedCases,
}

for _, set := range sets {
Expand Down Expand Up @@ -1419,3 +1420,8 @@ var kitchenSink = []TestCase{
{"kitchensink - field - invalid (transitive)", &cases.KitchenSinkMessage{Val: &cases.ComplexTestMsg{Const: "abcd", BoolConst: true, Nested: &cases.ComplexTestMsg{}}}, 14},
{"kitchensink - many - all non-message fields invalid", &cases.KitchenSinkMessage{Val: &cases.ComplexTestMsg{BoolConst: true, FloatVal: &wrapperspb.FloatValue{}, TsVal: &timestamppb.Timestamp{}, FloatConst: 8, AnyVal: &anypb.Any{TypeUrl: "asdf"}, RepTsVal: []*timestamppb.Timestamp{{Nanos: 1}}}}, 13},
}

var nestedCases = []TestCase {
{"nested wkt uuid - field - valid", &cases.WktLevelOne{Two: &cases.WktLevelOne_WktLevelTwo{Three: &cases.WktLevelOne_WktLevelTwo_WktLevelThree{Uuid: "f81d16ef-40e2-40c6-bebc-89aaf5292f9a"}}}, 0},
{"nested wkt uuid - field - invalid", &cases.WktLevelOne{Two: &cases.WktLevelOne_WktLevelTwo{Three: &cases.WktLevelOne_WktLevelTwo_WktLevelThree{Uuid: "not-a-valid-uuid"}}}, 1},
}

0 comments on commit 338a2fb

Please sign in to comment.