-
Notifications
You must be signed in to change notification settings - Fork 6
/
validation.proto
83 lines (71 loc) · 2.86 KB
/
validation.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
syntax = "proto2";
import "google/protobuf/descriptor.proto";
package validation;
option go_package = "github.com/neophenix/protoc-gen-validation;validation";
// The number here is supposed to be registered with google I think, I just did a random num gen
extend google.protobuf.FieldOptions {
optional FieldValidation field = 61032;
}
extend google.protobuf.MessageOptions {
optional MessageValidation message = 61032;
}
message FieldValidation {
// string options
// if value is defined, it can not be ""
optional bool not_empty_string = 1;
// the value has to be exactly this
optional string matches = 2;
// the value must contain this substring
optional string contains = 3;
// the value must match this regex
optional string regex = 4;
// integer options
// value must be less than or equal to this
optional int64 int_lte = 5;
// value must be greater than or equal to this
optional int64 int_gte = 6;
// value must equal this
optional int64 int_eq = 7;
// floating point type options
// value must be less than or equal to this
optional double float_lte = 8;
// value must be greater than or equal to this
optional double float_gte = 9;
// value must equal this
optional double float_eq = 10;
// more string options
// value must be at least this long
optional int64 min_len = 11;
// value must be at most this long
optional int64 max_len = 12;
// value must be exactly this long
optional int64 eq_len = 13;
// common option - define an error message instead of the default
// {field} and {value} can be used as placeholders and will be replaced with the actual values
optional string error = 14;
// more strings
// validate using github.com/google/uuid that this is an actual uuid
optional bool is_uuid = 15;
// validate using net/mail ParseAddress that this is a valid email
optional bool is_email = 16;
// validate using time.Parse that this is a valid date using the default format of YYYY-MM-DD (2006-01-02 in go's
// crazy syntax)
optional bool is_iso8601_date = 17;
// use strings.Trim to trim whitespace from the value
optional bool trim = 18;
// use strings.ToLower before validating
optional bool lc = 19;
// use strings.ToUpper before validating
optional bool uc = 20;
// common option - a function name that you presumably defined in the same package space as the
// code we generate that will be called via m.Field = FuncName(m.Field) allowing for any custom transformation
optional string transform_func = 21;
// do not generate validation code for a field; field type may not be supported i.e. oneof
optional bool do_not_validate = 22;
}
message MessageValidation {
// returns right away after the first error instead of the default of validating all fields
optional bool return_on_error = 1;
// uses strings.Trim on all strings in this message
optional bool trim_strings = 2;
}