-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinterfaces.go
More file actions
44 lines (37 loc) · 980 Bytes
/
interfaces.go
File metadata and controls
44 lines (37 loc) · 980 Bytes
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
package interfaces
import (
"context"
"iter"
"reflect"
"github.com/speakeasy-api/openapi/validation"
"go.yaml.in/yaml/v4"
)
type Validator[T any] interface {
*T
Validate(context.Context, ...validation.Option) []error
}
type Model[C any] interface {
Validate(context.Context, ...validation.Option) []error
GetCore() *C
}
type CoreModel interface {
Unmarshal(ctx context.Context, parentName string, node *yaml.Node) ([]error, error)
}
// sequencedMapInterface defines the interface that sequenced maps must implement
type SequencedMapInterface interface {
Init()
IsInitialized() bool
SetUntyped(key, value any) error
AllUntyped() iter.Seq2[any, any]
GetKeyType() reflect.Type
GetValueType() reflect.Type
Len() int
GetAny(key any) (any, bool)
SetAny(key, value any)
DeleteAny(key any)
KeysAny() iter.Seq[any]
}
func ImplementsInterface[T any](t reflect.Type) bool {
interfaceType := reflect.TypeOf((*T)(nil)).Elem()
return t.Implements(interfaceType)
}