mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
@@ -18,20 +18,20 @@ type nodeMap struct {
|
|||||||
// of files a node has come from.
|
// of files a node has come from.
|
||||||
type NodeOrigin struct {
|
type NodeOrigin struct {
|
||||||
// Node is the node in question
|
// Node is the node in question
|
||||||
Node *yaml.Node
|
Node *yaml.Node `json:"-"`
|
||||||
|
|
||||||
// Line is yhe original line of where the node was found in the original file
|
// Line is yhe original line of where the node was found in the original file
|
||||||
Line int
|
Line int `json:"line" yaml:"line"`
|
||||||
|
|
||||||
// Column is the original column of where the node was found in the original file
|
// Column is the original column of where the node was found in the original file
|
||||||
Column int
|
Column int `json:"column" yaml:"column"`
|
||||||
|
|
||||||
// AbsoluteLocation is the absolute path to the reference was extracted from.
|
// AbsoluteLocation is the absolute path to the reference was extracted from.
|
||||||
// This can either be an absolute path to a file, or a URL.
|
// This can either be an absolute path to a file, or a URL.
|
||||||
AbsoluteLocation string
|
AbsoluteLocation string `json:"absolute_location" yaml:"absolute_location"`
|
||||||
|
|
||||||
// Index is the index that contains the node that was located in.
|
// Index is the index that contains the node that was located in.
|
||||||
Index *SpecIndex
|
Index *SpecIndex `json:"-" yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNode returns a node from the spec based on a line and column. The second return var bool is true
|
// GetNode returns a node from the spec based on a line and column. The second return var bool is true
|
||||||
@@ -70,42 +70,6 @@ func (index *SpecIndex) MapNodes(rootNode *yaml.Node) {
|
|||||||
close(index.nodeMapCompleted)
|
close(index.nodeMapCompleted)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindNodeOrigin searches this index for a matching node. If the node is found, a NodeOrigin
|
|
||||||
// is returned, otherwise nil is returned.
|
|
||||||
func (index *SpecIndex) FindNodeOrigin(node *yaml.Node) *NodeOrigin {
|
|
||||||
if node != nil {
|
|
||||||
if index.nodeMap[node.Line] != nil {
|
|
||||||
if index.nodeMap[node.Line][node.Column] != nil {
|
|
||||||
foundNode := index.nodeMap[node.Line][node.Column]
|
|
||||||
if foundNode.Kind == yaml.DocumentNode {
|
|
||||||
foundNode = foundNode.Content[0]
|
|
||||||
}
|
|
||||||
match := true
|
|
||||||
if foundNode.Value != node.Value || foundNode.Kind != node.Kind || foundNode.Tag != node.Tag {
|
|
||||||
match = false
|
|
||||||
}
|
|
||||||
if len(foundNode.Content) == len(node.Content) {
|
|
||||||
for i := range foundNode.Content {
|
|
||||||
if foundNode.Content[i].Value != node.Content[i].Value {
|
|
||||||
match = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if match {
|
|
||||||
return &NodeOrigin{
|
|
||||||
Node: foundNode,
|
|
||||||
Line: node.Line,
|
|
||||||
Column: node.Column,
|
|
||||||
AbsoluteLocation: index.specAbsolutePath,
|
|
||||||
Index: index,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func enjoyALuxuryCruise(node *yaml.Node, nodeChan chan *nodeMap, root bool) {
|
func enjoyALuxuryCruise(node *yaml.Node, nodeChan chan *nodeMap, root bool) {
|
||||||
if len(node.Content) > 0 {
|
if len(node.Content) > 0 {
|
||||||
for _, child := range node.Content {
|
for _, child := range node.Content {
|
||||||
|
|||||||
@@ -32,5 +32,41 @@ func (r *Rolodex) FindNodeOrigin(node *yaml.Node) *NodeOrigin {
|
|||||||
searched++
|
searched++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return r.GetRootIndex().FindNodeOrigin(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindNodeOrigin searches this index for a matching node. If the node is found, a NodeOrigin
|
||||||
|
// is returned, otherwise nil is returned.
|
||||||
|
func (index *SpecIndex) FindNodeOrigin(node *yaml.Node) *NodeOrigin {
|
||||||
|
if node != nil {
|
||||||
|
if index.nodeMap[node.Line] != nil {
|
||||||
|
if index.nodeMap[node.Line][node.Column] != nil {
|
||||||
|
foundNode := index.nodeMap[node.Line][node.Column]
|
||||||
|
if foundNode.Kind == yaml.DocumentNode {
|
||||||
|
foundNode = foundNode.Content[0]
|
||||||
|
}
|
||||||
|
match := true
|
||||||
|
if foundNode.Value != node.Value || foundNode.Kind != node.Kind || foundNode.Tag != node.Tag {
|
||||||
|
match = false
|
||||||
|
}
|
||||||
|
if len(foundNode.Content) == len(node.Content) {
|
||||||
|
for i := range foundNode.Content {
|
||||||
|
if foundNode.Content[i].Value != node.Content[i].Value {
|
||||||
|
match = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if match {
|
||||||
|
return &NodeOrigin{
|
||||||
|
Node: foundNode,
|
||||||
|
Line: node.Line,
|
||||||
|
Column: node.Column,
|
||||||
|
AbsoluteLocation: index.specAbsolutePath,
|
||||||
|
Index: index,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user