/
known.go
83 lines (74 loc) · 2.61 KB
/
known.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
76
77
78
79
80
81
82
83
package openapi20
import (
"google.golang.org/protobuf/reflect/protoreflect"
)
const (
TypeInteger = "integer"
TypeNumber = "number"
TypeString = "string"
TypeBoolean = "boolean"
TypeArray = "array"
TypeObject = "object"
FormatNone = ""
FormatInt32 = "int32"
FormatInt64 = "int64"
FormatFloat = "float"
FormatDouble = "double"
FormatByte = "byte"
FormatBinary = "binary"
FormatDate = "date"
FormatDateTime = "date-time"
FormatPassword = "password"
protoAny = "google.protobuf.Any"
)
// Datatypes from https://swagger.io/specification/v2/
var (
IntegerType = DataTypeDesc{Type: TypeInteger, Format: FormatInt32}
LongType = DataTypeDesc{Type: TypeInteger, Format: FormatInt64}
Uint64Type = DataTypeDesc{Type: TypeString, Format: "uint64"} // non-standart type
FloatType = DataTypeDesc{Type: TypeNumber, Format: FormatFloat}
DoubleType = DataTypeDesc{Type: TypeNumber, Format: FormatDouble}
StringType = DataTypeDesc{Type: TypeString, Format: FormatNone}
ByteType = DataTypeDesc{Type: TypeString, Format: FormatByte}
BinaryType = DataTypeDesc{Type: TypeString, Format: FormatBinary}
BooleanType = DataTypeDesc{Type: TypeBoolean, Format: FormatNone}
DateType = DataTypeDesc{Type: TypeString, Format: FormatDate}
DateTimeType = DataTypeDesc{Type: TypeString, Format: FormatDateTime}
PasswordType = DataTypeDesc{Type: TypeString, Format: FormatPassword}
protoKindTypes = map[protoreflect.Kind]DataTypeDesc{
protoreflect.Int32Kind: IntegerType,
protoreflect.Sint32Kind: IntegerType,
protoreflect.Uint32Kind: LongType,
protoreflect.Int64Kind: LongType,
protoreflect.Sint64Kind: LongType,
protoreflect.Uint64Kind: Uint64Type,
protoreflect.FloatKind: FloatType,
protoreflect.DoubleKind: DoubleType,
protoreflect.BoolKind: BooleanType,
protoreflect.StringKind: StringType,
protoreflect.BytesKind: ByteType,
}
protoKnownTypes = map[protoreflect.FullName]DataTypeDesc{
"google.protobuf.StringValue": StringType,
"google.protobuf.BytesValue": ByteType,
"google.protobuf.BoolValue": BooleanType,
"google.protobuf.Int32Value": IntegerType,
"google.protobuf.Int64Value": LongType,
"google.protobuf.UInt32Value": LongType,
"google.protobuf.UInt64Value": Uint64Type,
"google.protobuf.FloatValue": FloatType,
"google.protobuf.DoubleValue": DoubleType,
"google.protobuf.Timestamp": DateTimeType,
"google.protobuf.Duration": StringType,
}
)
type DataTypeDesc struct {
Type string
Format string
}
func (d DataTypeDesc) Schema() *Schema {
return &Schema{Def: &SchemaDef{
Type: StringOrArray{d.Type},
Format: d.Format,
}}
}