That is an interesting question. With protocol buffers we have largely
stayed away from any kind of validation except for checking very basic
well-formedness. I think the usual practice is that if you need some kind
of validation, you just have to do it manually. The only kind of custom
validation we have is required fields in proto2, but after using that
feature for a while, a consensus arose that it was not a good idea, mostly
because it hindered schema evolution. There are lots of protos with
obsolete required fields in them, but you have to be careful to populate
them with dummy data nonetheless, and you can't just easily delete the
fields. I suspect that validation in general tends to go against protobuf's
goal of allowing easy schema evolution, because changing your validation
rules would require a lot of care to avoid causing breakages when you need
to interoperate with older code or even just messages on disk that were
serialized by older code.

On Wed, Sep 6, 2017 at 12:48 AM, Jay Bennett <[email protected]> wrote:

> Hi Protobufs team,
>
> I am currently using json-schema to verify my data in a REST+JSON network
> protocol. Obviously, protobufs is better. The .proto definitions are more
> clear, it's easier to maintain over time, and the code-gen from .proto
> files reduces boilerplate greatly.
>
> However, the json-schema has one advantage that I sorely miss, which is
> basic data validation rules for the contents of individual fields. I
> frequently use the string pattern match, int min/max value, and min/max
> count on arrays.
>
> I've created an issue of the feature request (https://github.com/google/
> protobuf/issues/3600) and an example in Go that demonstrates the kind of
> boilerplate validation code that lacking these features makes a developer
> have to write themselves: https://github.com/
> jaybennett89/protox-go-example.
>
> It really wouldn't be hard to have the generated Marshal/Unmarshal code
> automatically apply data validation rules, once a decent way of expressing
> them in the .proto file is agreed upon.
>
> I'm wondering, how do Google developers maintain these business rules in
> gRPC/Protobufs servers? For example, a maxItems 100 rule in a repeating
> field. Or a regex pattern match on a string field to ensure it complies
> with the format of some internal RFC.
>
> I think this feature would be simple and widely used. Protobufs implements
> almost all the same rules as json-schema, except these kind of rules.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to