-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
circular_reference_result.go
33 lines (28 loc) · 1.06 KB
/
circular_reference_result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package index
import (
"gopkg.in/yaml.v3"
"strings"
)
// CircularReferenceResult contains a circular reference found when traversing the graph.
type CircularReferenceResult struct {
Journey []*Reference
ParentNode *yaml.Node
Start *Reference
LoopIndex int
LoopPoint *Reference
IsArrayResult bool // if this result comes from an array loop.
PolymorphicType string // which type of polymorphic loop is this? (oneOf, anyOf, allOf)
IsPolymorphicResult bool // if this result comes from a polymorphic loop.
IsInfiniteLoop bool // if all the definitions in the reference loop are marked as required, this is an infinite circular reference, thus is not allowed.
}
// GenerateJourneyPath generates a string representation of the journey taken to find the circular reference.
func (c *CircularReferenceResult) GenerateJourneyPath() string {
buf := strings.Builder{}
for i, ref := range c.Journey {
if i > 0 {
buf.WriteString(" -> ")
}
buf.WriteString(ref.Name)
}
return buf.String()
}