/
design.go
112 lines (99 loc) · 2.54 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
package design
import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)
// goagen bootstrap -d github.com/freddygv/cassandra-wannabe/api/design
var _ = API("db", func() {
Title("The Cassandra-Wannabe API")
Description("CRUD API for a distributed database.")
License(func() {
Name("MIT")
URL("https://github.com/freddygv/cassandra-wannabe/blob/master/LICENSE")
})
Host("localhost:8080")
Scheme("http")
BasePath("/db/v1")
})
// RatingPayload is the input type
var RatingPayload = Type("RatingPayload", func() {
Attribute("movieId", Integer, func() {
Minimum(1)
Example(138493)
})
Attribute("userId", Integer, func() {
Minimum(1)
Example(56757)
})
Attribute("rating", Number, func() {
Minimum(0.5)
Maximum(5)
Example(3.5)
})
Required("movieId", "userId", "rating") // Bad request if one of these is missing
})
// RatingMedia is the output type
var RatingMedia = MediaType("application/cassandra.wannabe.rating+json", func() {
Description("A movie rating by a user")
TypeName("rating")
Reference(RatingPayload) // Some of these attributes are re-used from Payload type
Attributes(func() {
Attribute("movieId")
Attribute("userId")
Attribute("rating")
Required("movieId", "userId", "rating") // Rendering of these results must have non-zero values
})
View("default", func() {
Attribute("movieId")
Attribute("userId")
Attribute("rating")
})
})
// Resource groups endpoints with common properties together.
var _ = Resource("rating", func() {
Description("A movie rating by a user")
// Actions are the endpoints
Action("upsert", func() {
Description("Adds a rating record")
Routing(PUT("/"))
Payload(RatingPayload)
Response(NoContent)
Response(InternalServerError)
})
Action("read", func() {
Description("Retrieves a rating record")
Routing(GET("/:movieId/:userId"))
Params(func() {
Param("movieId", Integer)
Param("userId", Integer)
})
Response(OK, RatingMedia)
Response(NotFound)
Response(InternalServerError)
})
Action("delete", func() {
Description("Delete rating record")
Routing(DELETE("/:movieId/:userId"))
Params(func() {
Param("movieId", Integer)
Param("userId", Integer)
})
Response(Accepted)
Response(InternalServerError)
})
})
var _ = Resource("health", func() {
Action("health", func() {
Description("Status of the API.")
Routing(
GET("/status"),
)
Response(OK, "text/plain")
})
})
var _ = Resource("swagger", func() {
Origin("*", func() {
Methods("GET", "OPTIONS")
})
Files("/swagger.json", "public/swagger/swagger.json")
})