-
Notifications
You must be signed in to change notification settings - Fork 0
/
design.go
188 lines (146 loc) · 4.13 KB
/
design.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package design
import (
. "github.com/raphael/goa/design"
. "github.com/raphael/goa/design/dsl"
)
func init() {
API("gestalt", func() {
Title("Gestalt API")
BasePath("/v1")
License(func() {
Name("Apache 2.0")
URL("http://www.apache.org/licenses/LICENSE-2.0.html")
})
})
nameParam := func() { Param("name", String, func() { Pattern(`[a-zA-Z0-9\-]+`) }) }
valueParam := func() { Param("value", String, func() { Pattern(`[a-zA-Z0-9\-/]+`) }) }
Resource("schema", func() {
Description("deal with schema values")
BasePath("/schemas")
Action("list", func() {
Description("list the schemas present in the system")
Routing(GET(""))
Response(OK, func() {
Description("a list of schemas")
Media(CollectionOf(Schema, func() {
View("default")
}))
})
Response(InternalServerError)
})
Action("create", func() {
Description("write a schema to the backend")
Routing(POST(""))
Payload(Schema)
Params(func() {
Param("setDefaults", Boolean, "set defaults when creating", func() { Default(true) })
})
Response(Created, func() {
Description("schema was accepted")
Media(Schema)
})
Response(InternalServerError)
})
Action("get", func() {
Description("get a single schema")
Routing(GET("/:name"))
Params(nameParam)
Response(OK, func() {
Description("a single schema")
Media(Schema)
})
Response(NotFound)
Response(InternalServerError)
})
Action("update", func() {
Description("update an existing schema")
Routing(PUT("/:name"), POST("/:name"))
Payload(Schema)
Params(func() {
nameParam()
Param("setDefaults", Boolean, "set defaults when updating", func() { Default(false) })
})
Response(OK, func() {
Description("update accepted")
Media(Schema)
})
Response(NotFound)
Response(InternalServerError)
})
Action("delete", func() {
Description("delete an existing schema")
Routing(DELETE("/:name"))
Params(func() {
nameParam()
Param("deleteKeys", Boolean, "delete the keys for this app as well", func() { Default(false) })
})
Response(NoContent, func() { Description("deleted") })
Response(NotFound)
Response(InternalServerError)
})
Action("setDefaults", func() {
Description("set defaults on an existing schema")
Routing(POST("/:name/setDefaults"))
Params(nameParam)
Response(NoContent, func() { Description("defaults set") })
Response(NotFound)
Response(InternalServerError)
})
})
Resource("value", func() {
Description("deal with values as referenced by schemas")
BasePath("/schemas/:name/values")
Action("list", func() {
Description("list the values present in the K/V store")
Routing(GET(""))
Params(nameParam)
Response(OK, func() {
Description("a list of values")
Media("application/vnd.asteris.gestalt.values+json")
})
Response(NotFound)
Response(InternalServerError)
})
Action("writeAll", func() {
Description("write all the values at once")
Routing(PUT(""), POST(""))
Params(nameParam)
Response(OK, func() {
Description("the values which were written")
Media("application/vnd.asteris.gestalt.values+json")
})
Response(NotFound)
Response(InternalServerError)
})
Action("show", func() {
Description("show a single value")
Routing(GET("/*value"))
Params(func() { nameParam(); valueParam() })
Response(OK, func() {
Description("a single value")
Media("application/vnd.asteris.gestalt.value+json")
})
Response(NotFound)
Response(InternalServerError)
})
Action("write", func() {
Description("write a single value")
Routing(PUT("/*value"), POST("/*value"))
Params(func() { nameParam(); valueParam() })
Response(OK, func() {
Description("value was written")
Media("application/vnd.asteris.gestalt.value+json")
})
Response(NotFound)
Response(InternalServerError)
})
Action("delete", func() {
Description("delete a single value")
Routing(DELETE("/*value"))
Params(func() { nameParam(); valueParam() })
Response(NoContent, func() { Description("value was deleted") })
Response(NotFound)
Response(InternalServerError)
})
})
}