validateExpression checks whether the given expression is a valid expression within the given reference schema.
(ref schema.Schema, e filter.Expression)
| 31 | |
| 32 | // validateExpression checks whether the given expression is a valid expression within the given reference schema. |
| 33 | func validateExpression(ref schema.Schema, e filter.Expression) error { |
| 34 | switch e := e.(type) { |
| 35 | case *filter.ValuePath: |
| 36 | attr, err := validateAttributePath(ref, e.AttributePath) |
| 37 | if err != nil { |
| 38 | return nil |
| 39 | } |
| 40 | if err := validateExpression( |
| 41 | schema.Schema{ |
| 42 | ID: ref.ID, |
| 43 | Attributes: attr.SubAttributes(), |
| 44 | }, |
| 45 | e.ValueFilter, |
| 46 | ); err != nil { |
| 47 | return err |
| 48 | } |
| 49 | return nil |
| 50 | case *filter.AttributeExpression: |
| 51 | if _, err := validateAttributePath(ref, e.AttributePath); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | return nil |
| 55 | case *filter.LogicalExpression: |
| 56 | if err := validateExpression(ref, e.Left); err != nil { |
| 57 | return err |
| 58 | } |
| 59 | if err := validateExpression(ref, e.Right); err != nil { |
| 60 | return err |
| 61 | } |
| 62 | return nil |
| 63 | case *filter.NotExpression: |
| 64 | if err := validateExpression(ref, e.Expression); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | return nil |
| 68 | default: |
| 69 | panic(fmt.Sprintf("unknown expression type: %s", e)) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // validateSubAttribute checks whether the given attribute name is a attribute within the given reference attribute. |
| 74 | func validateSubAttribute(attr schema.CoreAttribute, subAttrName string) error { |
no test coverage detected
searching dependent graphs…