Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.9.11 #475

Merged
merged 12 commits into from
Apr 3, 2024
26 changes: 20 additions & 6 deletions functions/core/truthy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
vacuumUtils "github.com/daveshanley/vacuum/utils"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
"sort"
)

// Truthy is a rule that will determine if something is seen as 'true' (could be a 1 or "pizza", or actually 'true')
Expand Down Expand Up @@ -59,17 +60,30 @@ func (t *Truthy) RunRule(nodes []*yaml.Node, context model.RuleFunctionContext)
}

if !utils.IsNodeMap(fieldNode) && !utils.IsNodeArray(fieldNodeValue) && !utils.IsNodeMap(fieldNodeValue) {
var endNode *yaml.Node
if len(node.Content) > 0 {
endNode = node.Content[len(node.Content)-1]
} else {
endNode = node
if context.Index != nil {
origin := context.Index.FindNodeOrigin(node)
if origin != nil && origin.Line > 1 {
nm := context.Index.GetNodeMap()
var keys []int
for k := range nm {
keys = append(keys, k)
}

// Sort the keys slice.
sort.Ints(keys)

np := nm[origin.Line-1][keys[0]]

if np != nil {
node = np
}
}
}
results = append(results, model.RuleFunctionResult{
Message: vacuumUtils.SuppliedOrDefault(message,
fmt.Sprintf("%s: `%s` must be set", ruleMessage, context.RuleAction.Field)),
StartNode: node,
EndNode: vacuumUtils.BuildEndNode(endNode),
EndNode: vacuumUtils.BuildEndNode(node),
Path: pathValue,
Rule: context.Rule,
})
Expand Down
14 changes: 8 additions & 6 deletions functions/openapi/component_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ func (cd ComponentDescription) RunRule(_ []*yaml.Node, context model.RuleFunctio
key := schemaPairs.Key()

k, _ := low.FindItemInOrderedMapWithKey(key, components.Value.GoLow().Schemas.Value)
checkDescription(schemaValue.Schema.Value.Description,
key,
"schemas",
schemaValue.GenerateJSONPath(),
k.GetKeyNode(),
schemaValue)
if schemaValue.Schema != nil && schemaValue.Schema.Value != nil {
checkDescription(schemaValue.Schema.Value.Description,
key,
"schemas",
schemaValue.GenerateJSONPath(),
k.GetKeyNode(),
schemaValue)
}
}
}

Expand Down
25 changes: 22 additions & 3 deletions functions/openapi/examples_missing.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ func (em ExamplesMissing) RunRule(_ []*yaml.Node, context model.RuleFunctionCont
continue
}
if p.Value.Examples.Len() <= 0 && isExampleNodeNull([]*yaml.Node{p.Value.Example}) {
n := p.Value.GoLow().RootNode
if p.Value.GoLow().KeyNode != nil {
if p.Value.GoLow().KeyNode.Line == n.Line-1 {
n = p.Value.GoLow().KeyNode
}
}
results = append(results,
buildResult(vacuumUtils.SuppliedOrDefault(context.Rule.Message, "parameter is missing `examples` or `example`"),
p.GenerateJSONPath(),
p.Value.GoLow().RootNode, p))
n, p))
}
}
}
Expand All @@ -97,10 +103,16 @@ func (em ExamplesMissing) RunRule(_ []*yaml.Node, context model.RuleFunctionCont
continue
}
if h.Value.Examples.Len() <= 0 && isExampleNodeNull([]*yaml.Node{h.Value.Example}) {
n := h.Value.GoLow().RootNode
if h.Value.GoLow().KeyNode != nil {
if h.Value.GoLow().KeyNode.Line == n.Line-1 {
n = h.Value.GoLow().KeyNode
}
}
results = append(results,
buildResult(vacuumUtils.SuppliedOrDefault(context.Rule.Message, "header is missing `examples` or `example`"),
h.GenerateJSONPath(),
h.Value.GoLow().RootNode, h))
n, h))
}
}
}
Expand All @@ -109,10 +121,17 @@ func (em ExamplesMissing) RunRule(_ []*yaml.Node, context model.RuleFunctionCont
for i := range context.DrDocument.MediaTypes {
mt := context.DrDocument.MediaTypes[i]
if mt.Value.Examples.Len() <= 0 && isExampleNodeNull([]*yaml.Node{mt.Value.Example}) {

n := mt.Value.GoLow().RootNode
if mt.Value.GoLow().KeyNode != nil {
if mt.Value.GoLow().KeyNode.Line == n.Line-1 {
n = mt.Value.GoLow().KeyNode
}
}
results = append(results,
buildResult(vacuumUtils.SuppliedOrDefault(context.Rule.Message, "media type is missing `examples` or `example`"),
mt.GenerateJSONPath(),
mt.Value.GoLow().RootNode, mt))
n, mt))
}
}
}
Expand Down
Loading
Loading