@@ -36,7 +36,7 @@ const (
3636type AttributeExpression struct {
3737 AttributePath AttributePath
3838 Operator CompareOperator
39- CompareValue interface {}
39+ CompareValue any
4040}
4141
4242func (e AttributeExpression ) String () string {
@@ -54,12 +54,13 @@ func (e AttributeExpression) String() string {
5454
5555func (* AttributeExpression ) exprNode () {}
5656
57- // AttributePath represents an attribute path. Both URIPrefix and SubAttr are
58- // optional values and can be nil.
59- // e.g. urn:ietf:params:scim:schemas:core:2.0:User:name.givenName
60- // ^ ^ ^
61- // URIPrefix | SubAttribute
62- // AttributeName
57+ // AttributePath represents an attribute path with an optional URIPrefix and
58+ // SubAttribute.
59+ //
60+ // Example: urn:ietf:params:scim:schemas:core:2.0:User:name.givenName
61+ // - URIPrefix: urn:ietf:params:scim:schemas:core:2.0:User
62+ // - AttributeName: name
63+ // - SubAttribute: givenName
6364type AttributePath struct {
6465 URIPrefix * string
6566 AttributeName string
@@ -100,10 +101,10 @@ type CompareOperator string
100101
101102// Expression is a type to assign to implemented expressions.
102103// Valid expressions are:
103- // - ValuePath
104- // - AttributeExpression
105- // - LogicalExpression
106- // - NotExpression
104+ // - ValuePath
105+ // - AttributeExpression
106+ // - LogicalExpression
107+ // - NotExpression
107108type Expression interface {
108109 exprNode ()
109110}
@@ -115,7 +116,19 @@ type LogicalExpression struct {
115116}
116117
117118func (e LogicalExpression ) String () string {
118- return fmt .Sprintf ("%v %s %v" , e .Left , e .Operator , e .Right )
119+ left := fmt .Sprintf ("%v" , e .Left )
120+ if e .Operator == AND {
121+ if l , ok := e .Left .(* LogicalExpression ); ok && l .Operator == OR {
122+ left = fmt .Sprintf ("(%v)" , e .Left )
123+ }
124+ }
125+ right := fmt .Sprintf ("%v" , e .Right )
126+ if e .Operator == AND {
127+ if r , ok := e .Right .(* LogicalExpression ); ok && r .Operator == OR {
128+ right = fmt .Sprintf ("(%v)" , e .Right )
129+ }
130+ }
131+ return fmt .Sprintf ("%s %s %s" , left , e .Operator , right )
119132}
120133
121134func (* LogicalExpression ) exprNode () {}
@@ -134,12 +147,13 @@ func (e NotExpression) String() string {
134147
135148func (* NotExpression ) exprNode () {}
136149
137- // Path describes the target of a PATCH operation. Path can have an optional
150+ // Path describes the target of a PATCH operation with an optional
138151// ValueExpression and SubAttribute.
139- // e.g. members[value eq "2819c223-7f76-453a-919d-413861904646"].displayName
140- // ^ ^ ^
141- // | ValueExpression SubAttribute
142- // AttributePath
152+ //
153+ // Example: members[value eq "2819c223-..."].displayName
154+ // - AttributePath: members
155+ // - ValueExpression: value eq "2819c223-..."
156+ // - SubAttribute: displayName
143157type Path struct {
144158 AttributePath AttributePath
145159 ValueExpression Expression
0 commit comments