SpineEventEngine/validation

Support parentheses operator in `required_field` option

Opened this issue · 0 comments

In order to be able to specify the priority of the required_field logical operations explicitly, we should introduce support for the parentheses operator (()).

With such an operator it'll be possible to define such complex validation rules as e.g.:

message ComplexRequiredFields {

    option (required_field) = "(first | second) & (third | fourth) & fifth";

    repeated string first = 1;

    map<string,string> second = 2;

    oneof fields {
        string third = 3;
        string fourth = 4;
    }

    FifthField fifth = 5;

    message FifthField {
        string value = 1;
    }
}

In the message above we want the list or the map field and the oneof field and the message field to be required.

Without the parentheses operator, such a condition is just impossible to achieve. The following validation rule without parentheses will result in: first or second and third or fourth and fifth are required:

 option (required_field) = "first | second & third | fourth & fifth";

The notation above is actual equal to: "first | (second & third) | (fourth & fifth)".