-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboolean.go
More file actions
52 lines (44 loc) · 939 Bytes
/
boolean.go
File metadata and controls
52 lines (44 loc) · 939 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
45
46
47
48
49
50
51
52
package zed
import (
"github.com/ogen-go/ogen"
)
var _ Schema[bool] = (*BoolSchema)(nil)
type BoolSchema struct {
*baseSchema[any, bool]
}
// func (f *BoolSchema) Strict() *BoolSchema {
// f.strict = true
// return f
// }
func (s *BoolSchema) Validate(v any, _ SchemaValidationFlag) (out bool, e error) {
switch val := v.(type) {
case bool:
out = val
// case string:
// if s.strict {
// e = s.Err
// return
// }
// if strings.EqualFold(val, "true") {
// out = true
// } else if strings.EqualFold(val, "false") {
// out = false
// } else {
// e = s.Err
// }
default:
e = s.err
}
return
}
func (s *BoolSchema) ValidateGeneric(v any, flags SchemaValidationFlag) (any, error) {
return s.Validate(v, flags)
}
func (s *BoolSchema) ToSchema() *ogen.Schema {
return ogen.Bool()
}
func newBoolSchema(err string) *BoolSchema {
return &BoolSchema{
baseSchema: newBaseSchema[any, bool](err),
}
}