Skip to content

Commit

Permalink
Fix bug with recursion deep (grpc-ecosystem#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliaksei Burau authored and Evgeniy-L committed Nov 14, 2018
1 parent abfe1e7 commit 9a69f16
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions protoc-gen-swagger/genswagger/atlas_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,16 @@ func filterDefinitions() (newDefinitions spec.Definitions) {
}

func gatherDefinitionRefs(ref string, defs map[string]interface{}) map[string]struct{} {
var refs = map[string]struct{}{}
var refs = make(map[string]struct{})

gatherDefinitionRefsAux(ref, defs, refs)
gatherDefinitionRefsAux(refToName(ref), defs, refs)
return refs
}


func gatherDefinitionRefsAux(ref string, defs map[string]interface{}, refs map[string]struct{}) {
if _, ok := refs[refToName(ref)]; ok {
return
}

for r := range gatherRefs(defs[refToName(ref)]) {
refs[refToName(r)] = struct{}{}
for r := range gatherRefs(defs[ref]) {
refs[r] = struct{}{}
gatherDefinitionRefsAux(r, defs, refs)
}

Expand All @@ -524,7 +520,7 @@ func gatherRefs(v interface{}) map[string]struct{} {
case map[string]interface{}:
for k, vv := range v {
if k == "$ref" {
refs[vv.(string)] = struct{}{}
refs[refToName(vv.(string))] = struct{}{}
}

for rk := range gatherRefs(vv) {
Expand All @@ -533,7 +529,7 @@ func gatherRefs(v interface{}) map[string]struct{} {
}
case []interface{}:
for _, vv := range v {
for rk, _ := range gatherRefs(vv) {
for rk := range gatherRefs(vv) {
refs[rk] = struct{}{}
}
}
Expand Down

0 comments on commit 9a69f16

Please sign in to comment.