-
Notifications
You must be signed in to change notification settings - Fork 2
/
ref.go
75 lines (65 loc) · 1.38 KB
/
ref.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package openapi
import "github.com/chanced/uri"
const (
RefTypeUndefined RefType = iota
RefTypeComponent
RefTypeSchema
RefTypeSchemaDynamicRef
RefTypeSchemaRecursiveRef
RefTypeOperationRef
)
type RefType uint8
func (rk RefType) String() string {
switch rk {
case RefTypeComponent:
return "Reference"
case RefTypeSchema:
return "SchemaRef"
case RefTypeSchemaDynamicRef:
return "SchemaRef"
case RefTypeSchemaRecursiveRef:
return "SchemaRef"
case RefTypeOperationRef:
return "OperationRef"
default:
return "Undefined"
}
}
type Ref interface {
Node
URI() *uri.URI
IsResolved() bool
ResolvedNode() Node
// ReferencedKind returns the Kind for the referenced node
RefKind() Kind
// RefType returns the RefType for the reference
RefType() RefType
}
type ref interface {
Ref
resolve(v Node) error
}
// IsRef returns true for the following types:
// - *Reference
// - *SchemaRef
// - *OperationRef
func IsRef(node Node) bool {
switch node.Kind() {
case KindReference, KindSchemaRef, KindOperationRef:
_, ok := node.(Ref)
if !ok {
panic("node is not a Ref. This is a bug. Please report it to github.com/chanced/openapi")
}
return true
default:
return false
}
}
var (
_ Ref = (*SchemaRef)(nil)
_ ref = (*SchemaRef)(nil)
_ Ref = (*Reference[*Response])(nil)
_ ref = (*Reference[*Response])(nil)
_ Ref = (*OperationRef)(nil)
_ ref = (*OperationRef)(nil)
)