aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/go-openapi/spec/expander.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-openapi/spec/expander.go')
-rw-r--r--vendor/github.com/go-openapi/spec/expander.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/vendor/github.com/go-openapi/spec/expander.go b/vendor/github.com/go-openapi/spec/expander.go
index 140daf6e8..59a227059 100644
--- a/vendor/github.com/go-openapi/spec/expander.go
+++ b/vendor/github.com/go-openapi/spec/expander.go
@@ -91,7 +91,7 @@ func ResolveRefWithBase(root interface{}, ref *Ref, opts *ExpandOptions) (*Schem
return nil, err
}
specBasePath := ""
- if opts != nil {
+ if opts != nil && opts.RelativeBase != "" {
specBasePath, _ = absPath(opts.RelativeBase)
}
@@ -466,7 +466,7 @@ func ExpandSpec(spec *Swagger, options *ExpandOptions) error {
// getting the base path of the spec to adjust all subsequent reference resolutions
specBasePath := ""
- if options != nil {
+ if options != nil && options.RelativeBase != "" {
specBasePath, _ = absPath(options.RelativeBase)
}
@@ -535,6 +535,7 @@ func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error
if err != nil {
return err
}
+ defer os.Remove(file.Name())
switch r := root.(type) {
case *Schema:
@@ -561,8 +562,12 @@ func ExpandSchemaWithBasePath(schema *Schema, cache ResolutionCache, opts *Expan
}
if opts == nil {
- return errors.New("cannot expand schema without a basPath")
+ return errors.New("cannot expand schema without a base path")
}
+ if opts.RelativeBase == "" {
+ return errors.New("cannot expand schema with empty base path")
+ }
+
basePath, _ := absPath(opts.RelativeBase)
resolver, err := defaultSchemaLoader(nil, opts, cache)
@@ -647,14 +652,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))
@@ -663,8 +670,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)
}
}