forked from jakecoffman/crud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swagger.go
86 lines (73 loc) · 2.85 KB
/
swagger.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
package crud
type Swagger struct {
Swagger string `json:"swagger"`
Info Info `json:"info"`
BasePath string `json:"basePath,omitempty"`
Paths map[string]*Path `json:"paths"`
Definitions map[string]JsonSchema `json:"definitions"`
}
type Info struct {
Title string `json:"title"`
Version string `json:"version"`
}
type JsonSchema struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Properties map[string]JsonSchema `json:"properties,omitempty"`
Items *JsonSchema `json:"items,omitempty"`
Required []string `json:"required,omitempty"`
Example interface{} `json:"example,omitempty"`
Description string `json:"description,omitempty"`
Minimum float64 `json:"minimum,omitempty"`
Maximum float64 `json:"maximum,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Default interface{} `json:"default,omitempty"`
Pattern string `json:"pattern,omitempty"`
}
type Path struct {
Get *Operation `json:"get,omitempty"`
Post *Operation `json:"post,omitempty"`
Put *Operation `json:"put,omitempty"`
Delete *Operation `json:"delete,omitempty"`
Patch *Operation `json:"patch,omitempty"`
Options *Operation `json:"options,omitempty"`
}
type Operation struct {
Tags []string `json:"tags,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
Responses map[string]Response `json:"responses"`
Description string `json:"description"`
Summary string `json:"summary"`
}
type Parameter struct {
In string `json:"in"`
Name string `json:"name"`
// one of path, query, header, body, or form
Type string `json:"type,omitempty"`
Schema *Ref `json:"schema,omitempty"`
Required *bool `json:"required,omitempty"`
Description string `json:"description,omitempty"`
Minimum *float64 `json:"minimum,omitempty"`
Maximum *float64 `json:"maximum,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Pattern string `json:"pattern,omitempty"`
Default interface{} `json:"default,omitempty"`
Items *JsonSchema `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
}
type Ref struct {
Ref string `json:"$ref,omitempty"`
}
type Response struct {
Schema JsonSchema `json:"schema"`
Description string `json:"description"`
Example interface{} `json:"interface,omitempty"`
Ref *Ref `json:"$ref,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
var defaultResponse = map[string]Response{
"default": {
Schema: JsonSchema{Type: "string"},
Description: "Successful",
},
}