Skip to content

Commit 0d226c3

Browse files
daniel-corbettmjuraga
authored andcommitted
BUG/MAJOR: discovery: Add type assertion check to DiscoverChildPaths
A panic is caused when DiscoverChildPaths loops over endpoints that do not have a "get" method defined within embedded_spec.go. At time of this commit it is caused specifically by "/cluster/certificate" only having "post" and not a "get" defined. This commit adds a type assertion check to verify that v["get"] is of type map[string]interface{}. This fixes #85
1 parent 448d36e commit 0d226c3

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

misc/misc.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,19 @@ func DiscoverChildPaths(path string, spec json.RawMessage) (models.Endpoints, er
7676
paths := m["paths"].(map[string]interface{})
7777
for key, value := range paths {
7878
v := value.(map[string]interface{})
79-
g := v["get"].(map[string]interface{})
80-
title := g["summary"].(string)
81-
description := g["description"].(string)
79+
if g, ok := v["get"].(map[string]interface{}); ok {
80+
title := g["summary"].(string)
81+
description := g["description"].(string)
8282

83-
if strings.HasPrefix(key, path) && key != path {
84-
if len(strings.Split(key[len(path)+1:], "/")) == 1 {
85-
e := models.Endpoint{
86-
URL: key,
87-
Title: title,
88-
Description: description,
83+
if strings.HasPrefix(key, path) && key != path {
84+
if len(strings.Split(key[len(path)+1:], "/")) == 1 {
85+
e := models.Endpoint{
86+
URL: key,
87+
Title: title,
88+
Description: description,
89+
}
90+
es = append(es, &e)
8991
}
90-
es = append(es, &e)
9192
}
9293
}
9394
}

0 commit comments

Comments
 (0)