-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefs.go
47 lines (41 loc) · 1.68 KB
/
refs.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
package openapi
import "github.com/MarkRosemaker/errpath"
type (
// SchemaRef is a reference to a Schema or an actual Schema.
SchemaRef = refOrValue[Schema, *Schema]
// HeaderRef is a reference to a Header or an actual Header.
HeaderRef = refOrValue[Header, *Header]
// ResponseRef is a reference to a Response or an actual Response.
ResponseRef = refOrValue[Response, *Response]
// ParameterRef is a reference to a Parameter or an actual Parameter.
ParameterRef = refOrValue[Parameter, *Parameter]
// RequestBodyRef is a reference to a RequestBody or an actual RequestBody.
RequestBodyRef = refOrValue[RequestBody, *RequestBody]
// LinkRef is a reference to a Link or an actual Link.
LinkRef = refOrValue[Link, *Link]
// ExampleRef is a reference to an Example or an actual Example.
ExampleRef = refOrValue[Example, *Example]
// PathItemRef is a reference to a PathItem or an actual PathItem.
PathItemRef = refOrValue[PathItem, *PathItem]
// SecuritySchemeRef is a reference to a SecurityScheme or an actual SecurityScheme.
SecuritySchemeRef = refOrValue[SecurityScheme, *SecurityScheme]
// CallbackRef is a reference to a Callback or an actual Callback.
CallbackRef = refOrValue[Callback, *Callback]
// SchemaRefList is a slice of SchemaRef.
SchemaRefList []*SchemaRef
)
func getIndexRef[T any, O referencable[T]](ref *refOrValue[T, O]) int { return ref.idx }
func setIndexRef[T any, O referencable[T]](
ref *refOrValue[T, O], i int,
) *refOrValue[T, O] {
ref.idx = i
return ref
}
func (l *loader) resolveSchemaRefList(ss SchemaRefList) error {
for i, s := range ss {
if err := l.resolveSchemaRef(s); err != nil {
return &errpath.ErrIndex{Index: i, Err: err}
}
}
return nil
}