-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreferences_resolve.go
55 lines (42 loc) · 1.07 KB
/
references_resolve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package openapi
import (
"fmt"
"strings"
)
type ref []string
func (r ref) String() string {
return strings.Join(r, "/")
}
// collectResolveRefs expands references in a document that was just unmarshaled
func (l *loader) collectResolveRefs(doc *Document) error {
// collect all the references
l.collectDocument(doc, []string{"#"})
// resolve all the references
if err := l.resolveDocument(doc); err != nil {
return err
}
return nil
}
// resolveRef resolves a reference to a value or resolves the value itself
func resolveRef[T any, O referencable[T]](
r *refOrValue[T, O], values map[string]*T, resolveValue func(*T) error,
) error {
if r.Ref != nil && r.Value == nil {
if val, ok := values[r.Ref.Identifier]; ok {
r.Value = val
return nil
}
return fmt.Errorf("couldn't resolve %q", r.Ref.Identifier)
}
if resolveValue == nil {
return nil
}
return resolveValue(r.Value)
}
func (l *loader) collectPaths(ps Paths, ref ref) {
}
func (l *loader) resolveCallbacks(cs Callbacks) error {
return nil
}
func (l *loader) collectWebhooks(ws Webhooks, ref ref) {
}