-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
145 lines (130 loc) · 4.81 KB
/
schema.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package sadl
var BaseTypes = []string{
"Bool",
"Int8",
"Int16",
"Int32",
"Int64",
"Float32",
"Float64",
"Decimal",
"Bytes",
"String",
"Timestamp",
"UnitValue",
"UUID",
"Array",
"Map",
"Struct",
"Enum",
"Union",
"Any",
}
type Schema struct {
Sadl string `json:"sadl"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
Version string `json:"version,omitempty"`
Comment string `json:"comment,omitempty"`
Types []*TypeDef `json:"types,omitempty"`
Examples []*ExampleDef `json:"examples,omitempty"`
Operations []*OperationDef `json:"operations,omitempty"`
Http []*HttpDef `json:"http,omitempty"`
Base string `json:"base,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}
type TypeSpec struct {
Type string `json:"type"`
Pattern string `json:"pattern,omitempty"`
Values []string `json:"values,omitempty"`
MinSize *int64 `json:"minSize,omitempty"`
MaxSize *int64 `json:"maxSize,omitempty"`
Fields []*StructFieldDef `json:"fields,omitempty"`
Elements []*EnumElementDef `json:"elements,omitempty"`
Min *Decimal `json:"min,string,omitempty"`
Max *Decimal `json:"max,string,omitempty"`
Items string `json:"items,omitempty"`
Keys string `json:"keys,omitempty"`
Variants []*UnionVariantDef `json:"variants,omitempty"` //FIXME: a variant element, so comments/annotations can be attached
Unit string `json:"unit,omitempty"`
Value string `json:"value,omitempty"`
Reference string `json:"reference,omitempty"`
}
type TypeDef struct {
Name string `json:"name"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
TypeSpec
}
type EnumElementDef struct {
Symbol string `json:"symbol"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}
type StructFieldDef struct {
Name string `json:"name"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Required bool `json:"required,omitempty"`
Default interface{} `json:"default,omitempty"`
TypeSpec
}
type UnionVariantDef struct {
Name string `json:"name"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
TypeSpec
}
type ExampleDef struct {
Target string `json:"target"`
Name string `json:"name,omitempty"`
Example interface{} `json:"example,omitempty"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}
type OperationDef struct {
Name string `json:"name,omitempty"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Inputs []*OperationInput `json:"inputs,omitempty"`
Outputs []*OperationOutput `json:"outputs,omitempty"`
Exceptions []string `json:"exceptions,omitempty"`
}
type OperationInput struct {
StructFieldDef
}
type OperationOutput struct {
Name string `json:"name"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
TypeSpec
}
type HttpDef struct {
Name string `json:"name,omitempty"`
Resource string `json:"resource,omitempty"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Method string `json:"method"`
Path string `json:"path"`
Inputs []*HttpParamSpec `json:"inputs,omitempty"`
Expected *HttpExpectedSpec `json:"expected,omitempty"`
Exceptions []*HttpExceptionSpec `json:"exceptions,omitempty"`
}
type HttpParamSpec struct {
Header string `json:"header,omitempty"`
Query string `json:"query,omitempty"`
Path bool `json:"path,omitempty"`
StructFieldDef
}
type HttpExpectedSpec struct {
Outputs []*HttpParamSpec `json:"outputs,omitempty"`
Status int32 `json:"status"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}
type HttpExceptionSpec struct {
Type string `json:"type"`
Status int32 `json:"status"`
Comment string `json:"comment,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}