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

Required validation for scalar types

Open Yuto2000 opened this issue 4 years ago • 4 comments

Problem

When I set up a required field for a scalar type, It is tedious to add "optional" and check for nil or empty every time. Currently, for example, in the case of "string", I set more than one character and apply validation.

Suggestion

I would like to see a simple mandatory validation implemented for scalar types.

Yuto2000 avatar Nov 30 '22 00:11 Yuto2000

Hi @Yuto2000, thanks for your interest. Could you help me out with some examples of what you do currently and how you believe the syntax could be improved?

elliotmjackson avatar Dec 01 '22 18:12 elliotmjackson

Hi @elliotmjackson As shown below, I would like to see a simple required validation implemented.

optional string x = 1 [(validate.rules).string.required = true];
optional int32 x = 1 [(validate.rules).int32.required = true];

Yuto2000 avatar Dec 03 '22 03:12 Yuto2000

This feature would be very helpful.

daveamit avatar Dec 24 '22 18:12 daveamit

Hi @Yuto2000 - in protovalidate we have implemented this on all fields. Updating your example...

optional string x = 1 [(buf.validate.field).required = true];
optional int32 y = 2 [(buf.validate.field).required = true];

A beta release for Go is available now we're working on C++, Java, TypeScript, and Python versions currently.

elliotmjackson avatar Jun 08 '23 20:06 elliotmjackson