Skip to content

Commit 8fe113d

Browse files
committed
feat: request field validations in OpenAPI spec
Adds validations to every request field and marks more fields as required. PLAT-86
1 parent ef8e277 commit 8fe113d

File tree

20 files changed

+3896
-3880
lines changed

20 files changed

+3896
-3880
lines changed

api/design/api.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ var _ = g.Service("control-plane", func() {
148148
g.Payload(func() {
149149
g.Attribute("host_id", g.String, func() {
150150
g.Description("ID of the host to get.")
151+
g.Format(g.FormatUUID)
151152
g.Example("de3b1388-1f0c-42f1-a86c-59ab72f255ec")
152153
})
154+
155+
g.Required("host_id")
153156
})
154157
g.Result(Host)
155158
g.Error("cluster_not_initialized")
@@ -169,8 +172,11 @@ var _ = g.Service("control-plane", func() {
169172
g.Payload(func() {
170173
g.Attribute("host_id", g.String, func() {
171174
g.Description("ID of the host to remove.")
175+
g.Format(g.FormatUUID)
172176
g.Example("de3b1388-1f0c-42f1-a86c-59ab72f255ec")
173177
})
178+
179+
g.Required("host_id")
174180
})
175181
g.Error("cluster_not_initialized")
176182
g.Error("invalid_input")
@@ -222,8 +228,11 @@ var _ = g.Service("control-plane", func() {
222228
g.Payload(func() {
223229
g.Attribute("database_id", g.String, func() {
224230
g.Description("ID of the database to get.")
231+
g.Format(g.FormatUUID)
225232
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
226233
})
234+
235+
g.Required("database_id")
227236
})
228237
g.Result(Database, func() {
229238
g.View("default")
@@ -245,13 +254,17 @@ var _ = g.Service("control-plane", func() {
245254
g.Payload(func() {
246255
g.Attribute("database_id", g.String, func() {
247256
g.Description("ID of the database to update.")
257+
g.Format(g.FormatUUID)
248258
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
249259
})
250260
g.Attribute("force_update", g.Boolean, func() {
251261
g.Description("Force update the database even if the spec is the same.")
262+
g.Default(false)
252263
g.Example(true)
253264
})
254265
g.Attribute("request", UpdateDatabaseRequest)
266+
267+
g.Required("database_id", "request")
255268
})
256269
g.Result(UpdateDatabaseResponse)
257270
g.Error("cluster_not_initialized")
@@ -306,6 +319,7 @@ var _ = g.Service("control-plane", func() {
306319
})
307320
g.Attribute("node_name", g.String, func() {
308321
g.Description("Name of the node to back up.")
322+
g.Pattern(nodeNamePattern)
309323
g.Example("n1")
310324
})
311325
g.Attribute("options", BackupOptions)
@@ -487,5 +501,6 @@ var APIError = g.Type("APIError", func() {
487501
g.Description("A Control Plane API error.")
488502
g.ErrorName("name", g.String, "The name of the error.")
489503
g.Attribute("message", g.String, "The error message.")
504+
490505
g.Required("name", "message")
491506
})

api/design/backup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ var BackupOptions = g.Type("BackupOptions", func() {
1212
})
1313
g.Attribute("annotations", g.MapOf(g.String, g.String), func() {
1414
g.Description("Annotations for the backup.")
15+
g.MaxLength(32)
1516
g.Example(map[string]string{
1617
"key": "value",
1718
})
1819
})
1920
g.Attribute("backup_options", g.MapOf(g.String, g.String), func() {
2021
g.Description("Options for the backup.")
22+
g.MaxLength(32)
2123
g.Example(map[string]string{
2224
"archive-check": "n",
2325
})

api/design/cluster.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var ClusterJoinToken = g.Type("ClusterJoinToken", func() {
5151
var ClusterJoinRequest = g.Type("ClusterJoinRequest", func() {
5252
g.Attribute("token", g.String, func() {
5353
g.Description("Token to join the cluster.")
54+
g.Pattern(`^PGEDGE-[\w]{64}-[\w]{32}$`)
5455
g.Example("PGEDGE-dd440afcf5de20ef8e8cf54f6cb9f125fd55f90e64faa94b906130b31235e730-41e975f41d7ea61058f2fe2572cb52dd")
5556
})
5657
g.Attribute("host_id", g.String, func() {
@@ -60,6 +61,8 @@ var ClusterJoinRequest = g.Type("ClusterJoinRequest", func() {
6061
})
6162
g.Attribute("hostname", g.String, func() {
6263
g.Description("The hostname of the host that's joining the cluster.")
64+
g.MinLength(3)
65+
g.MaxLength(128)
6366
g.Example("ip-10-1-0-113.ec2.internal")
6467
})
6568
g.Attribute("ipv4_address", g.String, func() {
@@ -124,5 +127,5 @@ var ClusterJoinOptions = g.Type("ClusterJoinOptions", func() {
124127
g.Description("Credentials for the new host joining the cluster.")
125128
})
126129

127-
g.Required("peer")
130+
g.Required("peer", "credentials")
128131
})

0 commit comments

Comments
 (0)