Skip to content

Commit

Permalink
Fix expandSchema when basePath is empty
Browse files Browse the repository at this point in the history
Fixes kubernetes#45

Signed-off-by: Igor Zibarev <zibarev.i@gmail.com>
  • Loading branch information
hypnoglow committed Dec 18, 2017
1 parent aa90e7c commit 6ef9882
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,16 @@ func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader, ba
/* Ref also changes the resolution scope of children expandSchema */
if target.Ref.String() != "" {
/* Here the resolution scope is changed because a $ref was encountered */
newRef := normalizeFileRef(&target.Ref, basePath)
newBasePath := newRef.RemoteURI()
normalizedRef := normalizeFileRef(&target.Ref, basePath)
normalizedBasePath := normalizedRef.RemoteURI()

/* this means there is a circle in the recursion tree */
/* return the Ref */
if swag.ContainsStringsCI(parentRefs, newRef.String()) {
target.Ref = *newRef
if basePath != "" && swag.ContainsStringsCI(parentRefs, normalizedRef.String()) {
target.Ref = *normalizedRef
return &target, nil
}

debugLog("\nbasePath: %s", basePath)
b, _ := json.Marshal(target)
debugLog("calling Resolve with target: %s", string(b))
Expand All @@ -667,8 +669,8 @@ func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader, ba
}

if t != nil {
parentRefs = append(parentRefs, newRef.String())
return expandSchema(*t, parentRefs, resolver, newBasePath)
parentRefs = append(parentRefs, normalizedRef.String())
return expandSchema(*t, parentRefs, resolver, normalizedBasePath)
}
}

Expand Down

0 comments on commit 6ef9882

Please sign in to comment.