Skip to content

Commit c680187

Browse files
committed
Address #787
Dot notation was not supported for the `field` key. Now it is. So are numeric indices as well as string indices and the ability to escape any names with literal periods in them.
1 parent 104a118 commit c680187

File tree

11 files changed

+1020
-191
lines changed

11 files changed

+1020
-191
lines changed

functions/core/falsy.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ package core
55

66
import (
77
"fmt"
8+
"github.com/daveshanley/vacuum/model"
89
vacuumUtils "github.com/daveshanley/vacuum/utils"
910
"github.com/pb33f/doctor/model/high/v3"
10-
11-
"github.com/daveshanley/vacuum/model"
12-
"github.com/pb33f/libopenapi/utils"
1311
"go.yaml.in/yaml/v4"
1412
)
1513

@@ -65,8 +63,9 @@ func (f Falsy) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) []
6563
targetNode = node
6664
fieldName = "value"
6765
} else {
68-
// field specified - find it within the node
69-
fieldNode, targetNode = utils.FindKeyNode(context.RuleAction.Field, node.Content)
66+
// field specified - find it within the node (supports nested paths like "properties.data")
67+
result := vacuumUtils.FindFieldPath(context.RuleAction.Field, node.Content, vacuumUtils.FieldPathOptions{RecursiveFirstSegment: true})
68+
fieldNode, targetNode = result.KeyNode, result.ValueNode
7069
fieldName = context.RuleAction.Field
7170
}
7271

functions/core/length.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ func (l Length) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext) [
8181

8282
// check field type, is it a map? is it an array?
8383
if context.RuleAction.Field != "" {
84-
q, p = utils.FindFirstKeyNode(context.RuleAction.Field, []*yaml.Node{node}, 0)
85-
86-
// no luck? try again.
87-
if p == nil {
88-
q, p = utils.FindKeyNode(context.RuleAction.Field, []*yaml.Node{node})
89-
}
84+
// supports nested paths like "properties.data"
85+
result := vacuumUtils.FindFieldPath(context.RuleAction.Field, node.Content, vacuumUtils.FieldPathOptions{RecursiveFirstSegment: true})
86+
q, p = result.KeyNode, result.ValueNode
9087
} else {
9188
p = node
9289
}

0 commit comments

Comments
 (0)