protoc-gen-validate icon indicating copy to clipboard operation
protoc-gen-validate copied to clipboard

Support for well-known types like google.type.Decimal and google.type.Money

Open jschaf opened this issue 3 years ago • 5 comments

What's your stance on adding validation for well-known types? I'd like to add support for the following types:

  • google.type.Money.
  • google.protobuf.Timestamp
  • google.type.PostalAddress
  • google.type.Decimal

Alternately, is there a mechanism for adding validation on the fields of an external message?

jschaf avatar Dec 03 '21 07:12 jschaf

Many of the WKTs are covered (including google.protobuf.Timestamp), but I'm hesitant to suggest adding support for these other types as it's another dependency. The google.protobuf.* WKTs are almost always bundled and special-cased by generator plugins and runtime libs, but the google.type.* ones are not.

Alternately, is there a mechanism for adding validation on the fields of an external message?

Currently there is not, but it might be worth exploring side-loading validations for external types.

rodaine avatar Dec 06 '21 18:12 rodaine

Ah, so WKT refers exclusively to google.protobuf.*.

Feel free to close or repurpose for side-loading validations.

jschaf avatar Dec 06 '21 21:12 jschaf

We're also interested in side-loading validations. We're currently using additional types not covered by this project like:

  • google.type.TimeOfDay
  • google.type.DayOfWeek
  • google.type.Date

LionH avatar Dec 29 '21 16:12 LionH

We also wanted to side load validation as well. Currently we’re wrapping the Validate with another custom one.

do you have something in mind @rodaine? I was thinking on some kind of plugin system executed on build time.

glerchundi avatar Dec 29 '21 18:12 glerchundi

I'm casually working on a simple plugin system, having some troubles with an existing issue in imports, but the general gist is there https://github.com/EmbedFi/protoc-gen-validate/pull/7

daemonl avatar Jan 27 '22 21:01 daemonl

Does completed mean this is implemented or that it's out of scope?

jschaf avatar Oct 04 '22 18:10 jschaf

+1

loeffel-io avatar Oct 26 '22 09:10 loeffel-io

@daemonl i dont think i fully follow https://github.com/EmbedFi/protoc-gen-validate/pull/7, would you be able to share an example validating a well known type like a Date, Money, or just another complete pseudo example?

Thanks!

DustinJSilk avatar May 18 '23 10:05 DustinJSilk

It's been a while, but we are using it in this project: https://github.com/EmbedFi/protoc-gen-validate-embedfi

daemonl avatar May 18 '23 14:05 daemonl

It looks like this will be handled by V2, as described by the blog post: https://buf.build/blog/protoc-gen-validate-v1-and-v2/. I'll close this since v2 is probably the way forward.

jschaf avatar May 18 '23 17:05 jschaf