github.com/s7techlab/cckit@v0.10.5/third_party/mwitkow/go-proto-validators/validator.proto (about)

     1  // Copyright 2016 Michal Witkowski. All Rights Reserved.
     2  // See LICENSE for licensing terms.
     3  
     4  // Protocol Buffers extensions for defining auto-generateable validators for messages.
     5  
     6  // TODO(mwitkow): Add example.
     7  
     8  
     9  syntax = "proto2";
    10  package validator;
    11  
    12  import "google/protobuf/descriptor.proto";
    13  
    14  option go_package = "github.com/mwitkow/go-proto-validators;validator";
    15  
    16  // TODO(mwitkow): Email protobuf-global-extension-registry@google.com to get an extension ID.
    17  
    18  extend google.protobuf.FieldOptions {
    19    optional FieldValidator field = 65020;
    20  }
    21  
    22  extend google.protobuf.OneofOptions {
    23    optional OneofValidator oneof = 65021;
    24  }
    25  
    26  message FieldValidator {
    27    // Uses a Golang RE2-syntax regex to match the field contents.
    28    optional string regex = 1;
    29    // Field value of integer strictly greater than this value.
    30    optional int64 int_gt = 2;
    31    // Field value of integer strictly smaller than this value.
    32    optional int64 int_lt = 3;
    33    // Used for nested message types, requires that the message type exists.
    34    optional bool msg_exists = 4;
    35    // Human error specifies a user-customizable error that is visible to the user.
    36    optional string human_error = 5;
    37    // Field value of double strictly greater than this value.
    38    // Note that this value can only take on a valid floating point
    39    // value. Use together with float_epsilon if you need something more specific.
    40    optional double float_gt = 6;
    41    // Field value of double strictly smaller than this value.
    42    // Note that this value can only take on a valid floating point
    43    // value. Use together with float_epsilon if you need something more specific.
    44    optional double float_lt = 7;
    45    // Field value of double describing the epsilon within which
    46    // any comparison should be considered to be true. For example,
    47    // when using float_gt = 0.35, using a float_epsilon of 0.05
    48    // would mean that any value above 0.30 is acceptable. It can be
    49    // thought of as a {float_value_condition} +- {float_epsilon}.
    50    // If unset, no correction for floating point inaccuracies in
    51    // comparisons will be attempted.
    52    optional double float_epsilon = 8;
    53    // Floating-point value compared to which the field content should be greater or equal.
    54    optional double float_gte = 9;
    55    // Floating-point value compared to which the field content should be smaller or equal.
    56    optional double float_lte = 10;
    57    // Used for string fields, requires the string to be not empty (i.e different from "").
    58    optional bool string_not_empty = 11;
    59    // Repeated field with at least this number of elements.
    60    optional int64 repeated_count_min = 12;
    61    // Repeated field with at most this number of elements.
    62    optional int64 repeated_count_max = 13;
    63    // Field value of length greater than this value.
    64    optional int64 length_gt = 14;
    65    // Field value of length smaller than this value.
    66    optional int64 length_lt = 15;
    67    // Field value of length strictly equal to this value.
    68    optional int64 length_eq = 16;
    69    // Requires that the value is in the enum.
    70    optional bool is_in_enum = 17;
    71    // Ensures that a string value is in UUID format.
    72    // uuid_ver specifies the valid UUID versions. Valid values are: 0-5.
    73    // If uuid_ver is 0 all UUID versions are accepted.
    74    optional int32 uuid_ver = 18;
    75  }
    76  
    77  message OneofValidator {
    78    // Require that one of the oneof fields is set.
    79    optional bool required = 1;
    80  }