/
api.go
167 lines (154 loc) · 4.47 KB
/
api.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
package design
import . "goa.design/goa/v3/dsl"
var _ = API("cellar", func() {
Title("Cellar Service")
Description("HTTP service for managing your wine cellar")
Server("cellar", func() {
Description("cellar hosts the storage, sommelier and swagger services.")
Services("sommelier", "storage", "swagger")
Host("localhost", func() {
Description("default host")
URI("http://localhost:8000/cellar")
URI("grpc://localhost:8080/cellar")
})
Host("goa.design", func() {
Description("public host")
URI("https://goa.design/cellar")
URI("grpcs://goa.design/cellar")
})
})
})
var StoredBottle = ResultType("application/vnd.cellar.stored-bottle", func() {
Description("A StoredBottle describes a bottle retrieved by the storage service.")
Reference(Bottle)
TypeName("StoredBottle")
Attributes(func() {
Attribute("id", String, "ID is the unique id of the bottle.", func() {
Example("123abc")
Meta("rpc:tag", "8")
})
Field(2, "name")
Field(3, "winery")
Field(4, "vintage")
Field(5, "composition")
Field(6, "description")
Field(7, "rating")
})
View("default", func() {
Attribute("id")
Attribute("name")
Attribute("winery", func() {
View("tiny")
})
Attribute("vintage")
Attribute("composition")
Attribute("description")
Attribute("rating")
})
View("tiny", func() {
Attribute("id")
Attribute("name")
Attribute("winery", func() {
View("tiny")
})
})
Required("id", "name", "winery", "vintage")
})
var Bottle = Type("Bottle", func() {
Description("Bottle describes a bottle of wine to be stored.")
Attribute("name", String, "Name of bottle", func() {
MaxLength(100)
Example("Blue's Cuvee")
Meta("rpc:tag", "1")
})
Field(2, "winery", Winery, "Winery that produces wine")
Attribute("vintage", UInt32, "Vintage of bottle", func() {
Minimum(1900)
Maximum(2020)
Meta("rpc:tag", "3")
})
Field(4, "composition", ArrayOf(Component), "Composition is the list of grape varietals and associated percentage.")
Attribute("description", String, "Description of bottle", func() {
MaxLength(2000)
Example("Red wine blend with an emphasis on the Cabernet Franc grape and including other Bordeaux grape varietals and some Syrah")
Meta("rpc:tag", "5")
})
Attribute("rating", UInt32, "Rating of bottle from 1 (worst) to 5 (best)", func() {
Minimum(1)
Maximum(5)
Meta("rpc:tag", "6")
})
Required("name", "winery", "vintage")
})
var Winery = ResultType("Winery", func() {
Attributes(func() {
Attribute("name", String, "Name of winery", func() {
Example("Longoria")
Meta("rpc:tag", "1")
})
Attribute("region", String, "Region of winery", func() {
Pattern(`[a-zA-Z '\.]+`)
Example("Central Coast, California")
Meta("rpc:tag", "2")
})
Attribute("country", String, "Country of winery", func() {
Pattern(`[a-zA-Z '\.]+`)
Example("USA")
Meta("rpc:tag", "3")
})
Attribute("url", String, "Winery website URL", func() {
Pattern(`^(https?|ftp)://[^\s/$.?#].[^\s]*$`)
Example("http://www.longoriawine.com/")
Meta("rpc:tag", "4")
})
})
View("default", func() {
Attribute("name")
Attribute("region")
Attribute("country")
Attribute("url")
})
View("tiny", func() {
Attribute("name")
})
Required("name", "region", "country")
})
var Component = Type("Component", func() {
Attribute("varietal", String, "Grape varietal", func() {
Pattern(`[A-Za-z' ]+`)
MaxLength(100)
Example("Syrah")
Meta("rpc:tag", "1")
})
Attribute("percentage", UInt32, "Percentage of varietal in wine", func() {
Minimum(1)
Maximum(100)
Meta("rpc:tag", "2")
})
Required("varietal")
})
var NotFound = Type("NotFound", func() {
Description("NotFound is the type returned when attempting to show or delete a bottle that does not exist.")
Attribute("message", String, "Message of error", func() {
Meta("struct:error:name")
Example("bottle 1 not found")
Meta("rpc:tag", "1")
})
Field(2, "id", String, "ID of missing bottle")
Required("message", "id")
})
var Criteria = Type("Criteria", func() {
Description("Criteria described a set of criteria used to pick a bottle. All criteria are optional, at least one must be provided.")
Attribute("name", String, "Name of bottle to pick", func() {
Example("Blue's Cuvee")
Meta("rpc:tag", "1")
})
Attribute("varietal", ArrayOf(String), "Varietals in preference order", func() {
Example([]string{"pinot noir", "merlot", "cabernet franc"})
Meta("rpc:tag", "2")
})
Attribute("winery", String, "Winery of bottle to pick", func() {
Example("longoria")
Meta("rpc:tag", "3")
})
})