Vendor Update (#14496)
* update code.gitea.io/sdk/gitea v0.13.1 -> v0.13.2 * update github.com/go-swagger/go-swagger v0.25.0 -> v0.26.0 * update github.com/google/uuid v1.1.2 -> v1.2.0 * update github.com/klauspost/compress v1.11.3 -> v1.11.7 * update github.com/lib/pq 083382b7e6fc -> v1.9.0 * update github.com/markbates/goth v1.65.0 -> v1.66.1 * update github.com/mattn/go-sqlite3 v1.14.4 -> v1.14.6 * update github.com/mgechev/revive 246eac737dc7 -> v1.0.3 * update github.com/minio/minio-go/v7 v7.0.6 -> v7.0.7 * update github.com/niklasfasching/go-org v1.3.2 -> v1.4.0 * update github.com/olivere/elastic/v7 v7.0.21 -> v7.0.22 * update github.com/pquerna/otp v1.2.0 -> v1.3.0 * update github.com/xanzy/go-gitlab v0.39.0 -> v0.42.0 * update github.com/yuin/goldmark v1.2.1 -> v1.3.1
This commit is contained in:
parent
e45bf12a34
commit
d1353e1f7c
403 changed files with 29737 additions and 14357 deletions
176
vendor/github.com/go-openapi/spec/schema_loader.go
generated
vendored
176
vendor/github.com/go-openapi/spec/schema_loader.go
generated
vendored
|
@ -25,7 +25,14 @@ import (
|
|||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// PathLoader function to use when loading remote refs
|
||||
// PathLoader is a function to use when loading remote refs.
|
||||
//
|
||||
// This is a package level default. It may be overridden or bypassed by
|
||||
// specifying the loader in ExpandOptions.
|
||||
//
|
||||
// NOTE: if you are using the go-openapi/loads package, it will override
|
||||
// this value with its own default (a loader to retrieve YAML documents as
|
||||
// well as JSON ones).
|
||||
var PathLoader func(string) (json.RawMessage, error)
|
||||
|
||||
func init() {
|
||||
|
@ -41,19 +48,30 @@ func init() {
|
|||
// resolverContext allows to share a context during spec processing.
|
||||
// At the moment, it just holds the index of circular references found.
|
||||
type resolverContext struct {
|
||||
// circulars holds all visited circular references, which allows shortcuts.
|
||||
// NOTE: this is not just a performance improvement: it is required to figure out
|
||||
// circular references which participate several cycles.
|
||||
// circulars holds all visited circular references, to shortcircuit $ref resolution.
|
||||
//
|
||||
// This structure is privately instantiated and needs not be locked against
|
||||
// concurrent access, unless we chose to implement a parallel spec walking.
|
||||
circulars map[string]bool
|
||||
basePath string
|
||||
loadDoc func(string) (json.RawMessage, error)
|
||||
}
|
||||
|
||||
func newResolverContext(originalBasePath string) *resolverContext {
|
||||
func newResolverContext(expandOptions *ExpandOptions) *resolverContext {
|
||||
absBase, _ := absPath(expandOptions.RelativeBase)
|
||||
|
||||
// path loader may be overridden from option
|
||||
var loader func(string) (json.RawMessage, error)
|
||||
if expandOptions.PathLoader == nil {
|
||||
loader = PathLoader
|
||||
} else {
|
||||
loader = expandOptions.PathLoader
|
||||
}
|
||||
|
||||
return &resolverContext{
|
||||
circulars: make(map[string]bool),
|
||||
basePath: originalBasePath, // keep the root base path in context
|
||||
basePath: absBase, // keep the root base path in context
|
||||
loadDoc: loader,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,21 +80,20 @@ type schemaLoader struct {
|
|||
options *ExpandOptions
|
||||
cache ResolutionCache
|
||||
context *resolverContext
|
||||
loadDoc func(string) (json.RawMessage, error)
|
||||
}
|
||||
|
||||
func (r *schemaLoader) transitiveResolver(basePath string, ref Ref) (*schemaLoader, error) {
|
||||
func (r *schemaLoader) transitiveResolver(basePath string, ref Ref) *schemaLoader {
|
||||
if ref.IsRoot() || ref.HasFragmentOnly {
|
||||
return r, nil
|
||||
return r
|
||||
}
|
||||
|
||||
baseRef, _ := NewRef(basePath)
|
||||
baseRef := MustCreateRef(basePath)
|
||||
currentRef := normalizeFileRef(&ref, basePath)
|
||||
if strings.HasPrefix(currentRef.String(), baseRef.String()) {
|
||||
return r, nil
|
||||
return r
|
||||
}
|
||||
|
||||
// Set a new root to resolve against
|
||||
// set a new root against which to resolve
|
||||
rootURL := currentRef.GetURL()
|
||||
rootURL.Fragment = ""
|
||||
root, _ := r.cache.Get(rootURL.String())
|
||||
|
@ -85,16 +102,13 @@ func (r *schemaLoader) transitiveResolver(basePath string, ref Ref) (*schemaLoad
|
|||
// traversing multiple documents
|
||||
newOptions := r.options
|
||||
newOptions.RelativeBase = rootURL.String()
|
||||
debugLog("setting new root: %s", newOptions.RelativeBase)
|
||||
return defaultSchemaLoader(root, newOptions, r.cache, r.context)
|
||||
}
|
||||
|
||||
func (r *schemaLoader) updateBasePath(transitive *schemaLoader, basePath string) string {
|
||||
if transitive != r {
|
||||
debugLog("got a new resolver")
|
||||
if transitive.options != nil && transitive.options.RelativeBase != "" {
|
||||
basePath, _ = absPath(transitive.options.RelativeBase)
|
||||
debugLog("new basePath = %s", basePath)
|
||||
}
|
||||
}
|
||||
return basePath
|
||||
|
@ -103,17 +117,19 @@ func (r *schemaLoader) updateBasePath(transitive *schemaLoader, basePath string)
|
|||
func (r *schemaLoader) resolveRef(ref *Ref, target interface{}, basePath string) error {
|
||||
tgt := reflect.ValueOf(target)
|
||||
if tgt.Kind() != reflect.Ptr {
|
||||
return fmt.Errorf("resolve ref: target needs to be a pointer")
|
||||
return ErrResolveRefNeedsAPointer
|
||||
}
|
||||
|
||||
refURL := ref.GetURL()
|
||||
if refURL == nil {
|
||||
if ref.GetURL() == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var res interface{}
|
||||
var data interface{}
|
||||
var err error
|
||||
var (
|
||||
res interface{}
|
||||
data interface{}
|
||||
err error
|
||||
)
|
||||
|
||||
// Resolve against the root if it isn't nil, and if ref is pointing at the root, or has a fragment only which means
|
||||
// it is pointing somewhere in the root.
|
||||
root := r.root
|
||||
|
@ -122,12 +138,11 @@ func (r *schemaLoader) resolveRef(ref *Ref, target interface{}, basePath string)
|
|||
root, _, _, _ = r.load(baseRef.GetURL())
|
||||
}
|
||||
}
|
||||
|
||||
if (ref.IsRoot() || ref.HasFragmentOnly) && root != nil {
|
||||
data = root
|
||||
} else {
|
||||
baseRef := normalizeFileRef(ref, basePath)
|
||||
debugLog("current ref is: %s", ref.String())
|
||||
debugLog("current ref normalized file: %s", baseRef.String())
|
||||
data, _, _, err = r.load(baseRef.GetURL())
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -150,27 +165,29 @@ func (r *schemaLoader) load(refURL *url.URL) (interface{}, url.URL, bool, error)
|
|||
toFetch.Fragment = ""
|
||||
|
||||
var err error
|
||||
path := toFetch.String()
|
||||
if path == rootBase {
|
||||
path, err = absPath(rootBase)
|
||||
pth := toFetch.String()
|
||||
if pth == rootBase {
|
||||
pth, err = absPath(rootBase)
|
||||
if err != nil {
|
||||
return nil, url.URL{}, false, err
|
||||
}
|
||||
}
|
||||
normalized := normalizeAbsPath(path)
|
||||
normalized := normalizeAbsPath(pth)
|
||||
|
||||
data, fromCache := r.cache.Get(normalized)
|
||||
if !fromCache {
|
||||
b, err := r.loadDoc(normalized)
|
||||
b, err := r.context.loadDoc(normalized)
|
||||
if err != nil {
|
||||
debugLog("unable to load the document: %v", err)
|
||||
return nil, url.URL{}, false, err
|
||||
return nil, url.URL{}, false, fmt.Errorf("%s [%s]: %w", pth, normalized, err)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(b, &data); err != nil {
|
||||
var doc interface{}
|
||||
if err := json.Unmarshal(b, &doc); err != nil {
|
||||
return nil, url.URL{}, false, err
|
||||
}
|
||||
r.cache.Set(normalized, data)
|
||||
r.cache.Set(normalized, doc)
|
||||
|
||||
return doc, toFetch, fromCache, nil
|
||||
}
|
||||
|
||||
return data, toFetch, fromCache, nil
|
||||
|
@ -185,17 +202,20 @@ func (r *schemaLoader) isCircular(ref *Ref, basePath string, parentRefs ...strin
|
|||
foundCycle = true
|
||||
return
|
||||
}
|
||||
foundCycle = swag.ContainsStringsCI(parentRefs, normalizedRef)
|
||||
foundCycle = swag.ContainsStringsCI(parentRefs, normalizedRef) // TODO(fred): normalize windows url and remove CI equality
|
||||
if foundCycle {
|
||||
r.context.circulars[normalizedRef] = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Resolve resolves a reference against basePath and stores the result in target
|
||||
// Resolve is not in charge of following references, it only resolves ref by following its URL
|
||||
// if the schema that ref is referring to has more refs in it. Resolve doesn't resolve them
|
||||
// if basePath is an empty string, ref is resolved against the root schema stored in the schemaLoader struct
|
||||
// Resolve resolves a reference against basePath and stores the result in target.
|
||||
//
|
||||
// Resolve is not in charge of following references: it only resolves ref by following its URL.
|
||||
//
|
||||
// If the schema the ref is referring to holds nested refs, Resolve doesn't resolve them.
|
||||
//
|
||||
// If basePath is an empty string, ref is resolved against the root schema stored in the schemaLoader struct
|
||||
func (r *schemaLoader) Resolve(ref *Ref, target interface{}, basePath string) error {
|
||||
return r.resolveRef(ref, target, basePath)
|
||||
}
|
||||
|
@ -212,30 +232,32 @@ func (r *schemaLoader) deref(input interface{}, parentRefs []string, basePath st
|
|||
case *PathItem:
|
||||
ref = &refable.Ref
|
||||
default:
|
||||
return fmt.Errorf("deref: unsupported type %T", input)
|
||||
return fmt.Errorf("unsupported type: %T: %w", input, ErrDerefUnsupportedType)
|
||||
}
|
||||
|
||||
curRef := ref.String()
|
||||
if curRef != "" {
|
||||
normalizedRef := normalizeFileRef(ref, basePath)
|
||||
normalizedBasePath := normalizedRef.RemoteURI()
|
||||
|
||||
if r.isCircular(normalizedRef, basePath, parentRefs...) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := r.resolveRef(ref, input, basePath); r.shouldStopOnError(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
// NOTE(fredbi): removed basePath check => needs more testing
|
||||
if ref.String() != "" && ref.String() != curRef {
|
||||
parentRefs = append(parentRefs, normalizedRef.String())
|
||||
return r.deref(input, parentRefs, normalizedBasePath)
|
||||
}
|
||||
if curRef == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
normalizedRef := normalizeFileRef(ref, basePath)
|
||||
normalizedBasePath := normalizedRef.RemoteURI()
|
||||
|
||||
if r.isCircular(normalizedRef, basePath, parentRefs...) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := r.resolveRef(ref, input, basePath); r.shouldStopOnError(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
if ref.String() == "" || ref.String() == curRef {
|
||||
// done with rereferencing
|
||||
return nil
|
||||
}
|
||||
|
||||
parentRefs = append(parentRefs, normalizedRef.String())
|
||||
return r.deref(input, parentRefs, normalizedBasePath)
|
||||
}
|
||||
|
||||
func (r *schemaLoader) shouldStopOnError(err error) bool {
|
||||
|
@ -250,30 +272,48 @@ func (r *schemaLoader) shouldStopOnError(err error) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (r *schemaLoader) setSchemaID(target interface{}, id, basePath string) (string, string) {
|
||||
debugLog("schema has ID: %s", id)
|
||||
|
||||
// handling the case when id is a folder
|
||||
// remember that basePath has to point to a file
|
||||
var refPath string
|
||||
if strings.HasSuffix(id, "/") {
|
||||
// path.Clean here would not work correctly if there is a scheme (e.g. https://...)
|
||||
refPath = fmt.Sprintf("%s%s", id, "placeholder.json")
|
||||
} else {
|
||||
refPath = id
|
||||
}
|
||||
|
||||
// updates the current base path
|
||||
// * important: ID can be a relative path
|
||||
// * registers target to be fetchable from the new base proposed by this id
|
||||
newBasePath := normalizePaths(refPath, basePath)
|
||||
|
||||
// store found IDs for possible future reuse in $ref
|
||||
r.cache.Set(newBasePath, target)
|
||||
|
||||
return newBasePath, refPath
|
||||
}
|
||||
|
||||
func defaultSchemaLoader(
|
||||
root interface{},
|
||||
expandOptions *ExpandOptions,
|
||||
cache ResolutionCache,
|
||||
context *resolverContext) (*schemaLoader, error) {
|
||||
context *resolverContext) *schemaLoader {
|
||||
|
||||
if cache == nil {
|
||||
cache = resCache
|
||||
}
|
||||
if expandOptions == nil {
|
||||
expandOptions = &ExpandOptions{}
|
||||
}
|
||||
absBase, _ := absPath(expandOptions.RelativeBase)
|
||||
|
||||
if context == nil {
|
||||
context = newResolverContext(absBase)
|
||||
context = newResolverContext(expandOptions)
|
||||
}
|
||||
|
||||
return &schemaLoader{
|
||||
root: root,
|
||||
options: expandOptions,
|
||||
cache: cache,
|
||||
cache: cacheOrDefault(cache),
|
||||
context: context,
|
||||
loadDoc: func(path string) (json.RawMessage, error) {
|
||||
debugLog("fetching document at %q", path)
|
||||
return PathLoader(path)
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue