From e803e03eaf59c91eb5897a36395f66e7a4081c65 Mon Sep 17 00:00:00 2001 From: Hylke Visser Date: Tue, 5 May 2020 18:14:28 +0200 Subject: [PATCH 1/3] Move lyft_validate to envoyproxy_validate --- .../envoyproxy_validate.go} | 0 .../envoyproxy_validate_test.go} | 0 extensions/lyft_validate/alias.go | 9 +++++++++ 3 files changed, 9 insertions(+) rename extensions/{lyft_validate/lyft_validate.go => envoyproxy_validate/envoyproxy_validate.go} (100%) rename extensions/{lyft_validate/lyft_validate_test.go => envoyproxy_validate/envoyproxy_validate_test.go} (100%) create mode 100644 extensions/lyft_validate/alias.go diff --git a/extensions/lyft_validate/lyft_validate.go b/extensions/envoyproxy_validate/envoyproxy_validate.go similarity index 100% rename from extensions/lyft_validate/lyft_validate.go rename to extensions/envoyproxy_validate/envoyproxy_validate.go diff --git a/extensions/lyft_validate/lyft_validate_test.go b/extensions/envoyproxy_validate/envoyproxy_validate_test.go similarity index 100% rename from extensions/lyft_validate/lyft_validate_test.go rename to extensions/envoyproxy_validate/envoyproxy_validate_test.go diff --git a/extensions/lyft_validate/alias.go b/extensions/lyft_validate/alias.go new file mode 100644 index 00000000..985a0cf9 --- /dev/null +++ b/extensions/lyft_validate/alias.go @@ -0,0 +1,9 @@ +package extensions + +import evp "github.com/pseudomuto/protoc-gen-doc/extensions/envoyproxy_validate" + +// ValidateRule represents a single validator rule from the (validate.rules) method option extension. +type ValidateRule = evp.ValidateRule + +// ValidateExtension contains the rules set by the (validate.rules) method option extension. +type ValidateExtension = evp.ValidateExtension From 09a73bee59d86586b7a85176e51c2f8f5607c9c6 Mon Sep 17 00:00:00 2001 From: Hylke Visser Date: Tue, 5 May 2020 18:14:29 +0200 Subject: [PATCH 2/3] Fix handling of slice rules of envoyproxy/validate --- extensions/envoyproxy_validate/envoyproxy_validate.go | 1 + extensions/envoyproxy_validate/envoyproxy_validate_test.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/extensions/envoyproxy_validate/envoyproxy_validate.go b/extensions/envoyproxy_validate/envoyproxy_validate.go index c5b83e57..70941f65 100644 --- a/extensions/envoyproxy_validate/envoyproxy_validate.go +++ b/extensions/envoyproxy_validate/envoyproxy_validate.go @@ -73,6 +73,7 @@ func flattenRules(prefix string, vv reflect.Value) (rules []ValidateRule) { if vv.Len() == 0 { return nil } + fallthrough default: rules = append(rules, ValidateRule{Name: prefix, Value: vv.Interface()}) } diff --git a/extensions/envoyproxy_validate/envoyproxy_validate_test.go b/extensions/envoyproxy_validate/envoyproxy_validate_test.go index 3d5f3f10..7c6cae87 100644 --- a/extensions/envoyproxy_validate/envoyproxy_validate_test.go +++ b/extensions/envoyproxy_validate/envoyproxy_validate_test.go @@ -15,6 +15,7 @@ func TestTransform(t *testing.T) { Type: &validate.FieldRules_String_{ String_: &validate.StringRules{ MinLen: proto.Uint64(1), + NotIn: []string{"invalid"}, }, }, } @@ -25,5 +26,6 @@ func TestTransform(t *testing.T) { rules := transformed["validate.rules"].(ValidateExtension).Rules() require.Equal(t, rules, []ValidateRule{ {Name: "string.min_len", Value: uint64(1)}, + {Name: "string.not_in", Value: []string{"invalid"}}, }) } From b62fb0e5c45421141cf24d53c4f77fefda7337a3 Mon Sep 17 00:00:00 2001 From: Hylke Visser Date: Tue, 5 May 2020 18:14:29 +0200 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49f8c88b..b3d04cfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed * Stripped unnecessary whitespace from markdown templates +* Renamed `lyft_validate` extension to `envoyproxy_validate` +* Fixed `envoyproxy_validate` rules with slice values such as `in` and `not_in` ## [v1.3.1](https://github.com/pseudomuto/protoc-gen-doc/compare/v1.3.0...v1.3.1)