func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error {
	cache = cacheOrDefault(cache)
	if root == nil {
		root = schema
	}
	opts := &ExpandOptions{
		RelativeBase:    baseForRoot(root, cache),
		SkipSchemas:     false,
		ContinueOnError: false,
	}
	return ExpandSchemaWithBasePath(schema, cache, opts)
}
ExpandSchema expands the refs in the schema object with reference to the root object.

go-openapi/validate uses this function.

Notice that it is impossible to reference a json schema in a different document other than root
(use ExpandSchemaWithBasePath to resolve external references).

Setting the cache is optional and this parameter may safely be left to nil.
package spec
import (
	"encoding/json"
	"fmt"
)
type ExpandOptions struct {
	RelativeBase        string                                 
	SkipSchemas         bool                                   
	ContinueOnError     bool                                   
	PathLoader          func(string) (json.RawMessage, error) `json:"-"`  
	AbsoluteCircularRef bool                                   
}
func optionsOrDefault(opts *ExpandOptions) *ExpandOptions {
	if opts != nil {
		clone := *opts  
		if clone.RelativeBase != "" {
			clone.RelativeBase = normalizeBase(clone.RelativeBase)
		}
		return &clone
	}
	return &ExpandOptions{}
}
func ExpandSpec(spec *Swagger, options *ExpandOptions) error {
	options = optionsOrDefault(options)
	resolver := defaultSchemaLoader(spec, options, nil, nil)
	specBasePath := options.RelativeBase
	if !options.SkipSchemas {
		for key, definition := range spec.Definitions {
			parentRefs := make([]string, 0, 10)
			parentRefs = append(parentRefs, fmt.Sprintf("#/definitions/%s", key))
			def, err := expandSchema(definition, parentRefs, resolver, specBasePath)
			if resolver.shouldStopOnError(err) {
				return err
			}
			if def != nil {
				spec.Definitions[key] = *def
			}
		}
	}
	for key := range spec.Parameters {
		parameter := spec.Parameters[key]
		if err := expandParameterOrResponse(&parameter, resolver, specBasePath); resolver.shouldStopOnError(err) {
			return err
		}
		spec.Parameters[key] = parameter
	}
	for key := range spec.Responses {
		response := spec.Responses[key]
		if err := expandParameterOrResponse(&response, resolver, specBasePath); resolver.shouldStopOnError(err) {
			return err
		}
		spec.Responses[key] = response
	}
	if spec.Paths != nil {
		for key := range spec.Paths.Paths {
			pth := spec.Paths.Paths[key]
			if err := expandPathItem(&pth, resolver, specBasePath); resolver.shouldStopOnError(err) {
				return err
			}
			spec.Paths.Paths[key] = pth
		}
	}
	return nil
}
const rootBase = ".root"
func baseForRoot(root interface{}, cache ResolutionCache) string {
	if root == nil {
		return ""
	}
	normalizedBase := normalizeBase(rootBase)
	cache.Set(normalizedBase, root)
	return normalizedBase
}