-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_type_format.go
69 lines (62 loc) · 1.88 KB
/
data_type_format.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
package openapi
import (
"slices"
"github.com/MarkRosemaker/errpath"
)
// Format defines additional formats to provide fine detail for primitive data types.
type Format string
const (
// FormatInt32 represents a signed 32 bits integer.
FormatInt32 Format = "int32"
// FormatInt64 represents a signed 64 bits integer.
FormatInt64 Format = "int64"
// FormatFloat represents a float number.
FormatFloat Format = "float"
// FormatDouble represents a double number.
FormatDouble Format = "double"
// FormatByte represents a byte.
FormatByte Format = "byte"
// FormatBinary represents a binary.
FormatBinary Format = "binary"
// FormatDate represents a date.
FormatDate Format = "date"
// FormatDateTime represents a date-time.
FormatDateTime Format = "date-time"
// FormatDuration represents a duration.
FormatDuration Format = "duration"
// FormatEmail represents an email.
FormatEmail Format = "email"
// FormatPassword represents a password. It's a hint to UIs to obscure input.
FormatPassword Format = "password"
// FormatUUID represents a UUID.
FormatUUID Format = "uuid"
// FormatURI represents a URI.
FormatURI Format = "uri"
// FormatURIRef represents a URI reference.
FormatURIRef Format = "uriref"
// FormatZipCode represents a zip code.
FormatZipCode Format = "zip-code"
// FormatIPv4 represents an IPv4 address.
FormatIPv4 Format = "ipv4"
// FormatIPv6 represents an IPv6 address.
FormatIPv6 Format = "ipv6"
)
var allFormats = []Format{
FormatInt32, FormatInt64, FormatFloat, FormatDouble,
FormatByte, FormatBinary,
FormatDate, FormatDateTime, FormatDuration,
FormatEmail, FormatPassword,
FormatUUID,
FormatURI, FormatURIRef, FormatZipCode,
FormatIPv4, FormatIPv6,
}
// Validate validates the format.
func (f Format) Validate() error {
if slices.Contains(allFormats, f) {
return nil
}
return &errpath.ErrInvalid[Format]{
Value: f,
Enum: allFormats,
}
}