Skip to content

Commit c42a384

Browse files
fix: use model's RootNode instead of parameter for consistency in GetMapKeyNodeOrRoot methods
1 parent b1bc1fe commit c42a384

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

openapi/core/callbacks.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ func (c *Callback) GetMapKeyNodeOrRoot(key string, rootNode *yaml.Node) *yaml.No
2525
return rootNode
2626
}
2727

28-
for i := 0; i < len(rootNode.Content); i += 2 {
29-
if rootNode.Content[i].Value == key {
30-
return rootNode.Content[i]
28+
if c.RootNode == nil {
29+
return rootNode
30+
}
31+
32+
for i := 0; i < len(c.RootNode.Content); i += 2 {
33+
if c.RootNode.Content[i].Value == key {
34+
return c.RootNode.Content[i]
3135
}
3236
}
3337

openapi/core/paths.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ func (p *Paths) GetMapKeyNodeOrRoot(key string, rootNode *yaml.Node) *yaml.Node
2525
return rootNode
2626
}
2727

28-
for i := 0; i < len(rootNode.Content); i += 2 {
29-
if rootNode.Content[i].Value == key {
30-
return rootNode.Content[i]
28+
if p.RootNode == nil {
29+
return rootNode
30+
}
31+
32+
for i := 0; i < len(p.RootNode.Content); i += 2 {
33+
if p.RootNode.Content[i].Value == key {
34+
return p.RootNode.Content[i]
3135
}
3236
}
3337

@@ -66,9 +70,13 @@ func (p *PathItem) GetMapKeyNodeOrRoot(key string, rootNode *yaml.Node) *yaml.No
6670
return rootNode
6771
}
6872

69-
for i := 0; i < len(rootNode.Content); i += 2 {
70-
if rootNode.Content[i].Value == key {
71-
return rootNode.Content[i]
73+
if p.RootNode == nil {
74+
return rootNode
75+
}
76+
77+
for i := 0; i < len(p.RootNode.Content); i += 2 {
78+
if p.RootNode.Content[i].Value == key {
79+
return p.RootNode.Content[i]
7280
}
7381
}
7482

openapi/core/responses.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ func (r *Responses) GetMapKeyNodeOrRoot(key string, rootNode *yaml.Node) *yaml.N
2626
return rootNode
2727
}
2828

29-
for i := 0; i < len(rootNode.Content); i += 2 {
30-
if rootNode.Content[i].Value == key {
31-
return rootNode.Content[i]
29+
if r.RootNode == nil {
30+
return rootNode
31+
}
32+
33+
for i := 0; i < len(r.RootNode.Content); i += 2 {
34+
if r.RootNode.Content[i].Value == key {
35+
return r.RootNode.Content[i]
3236
}
3337
}
3438

openapi/core/security.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ func (s *SecurityRequirement) GetMapKeyNodeOrRoot(key string, rootNode *yaml.Nod
3737
return rootNode
3838
}
3939

40-
for i := 0; i < len(rootNode.Content); i += 2 {
41-
if rootNode.Content[i].Value == key {
42-
return rootNode.Content[i]
40+
if s.RootNode == nil {
41+
return rootNode
42+
}
43+
44+
for i := 0; i < len(s.RootNode.Content); i += 2 {
45+
if s.RootNode.Content[i].Value == key {
46+
return s.RootNode.Content[i]
4347
}
4448
}
4549

0 commit comments

Comments
 (0)