Skip to content

Commit 243cbd2

Browse files
committed
chore: openapi swagger
1 parent 52a54cc commit 243cbd2

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

apps/backend/src/app.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { WebhookEventsHandler } from "@undb/webhook"
2222
import { Elysia } from "elysia"
2323
import { all } from "radash"
2424
import { v4 } from "uuid"
25+
import * as pkg from "../../../package.json"
2526
import { Auth, OpenAPI, Realtime, SpaceModule, TableModule, Web } from "./modules"
2627
import { FileService } from "./modules/file/file"
2728
import { OpenTelemetryModule } from "./modules/opentelemetry/opentelemetry.module"
@@ -103,7 +104,21 @@ export const app = new Elysia()
103104
})
104105
.use(cors())
105106
.use(html())
106-
.use(swagger())
107+
.use(
108+
swagger({
109+
path: "/openapi",
110+
excludeStaticFile: true,
111+
exclude: new RegExp(/^(?!.*\/api\/bases).*/),
112+
documentation: {
113+
info: {
114+
title: "Undb OpenAPI Documentation",
115+
version: pkg.version,
116+
},
117+
118+
tags: [{ name: "Record", description: "Record operations" }],
119+
},
120+
}),
121+
)
107122
.derive(auth.store())
108123
.onError((ctx) => {
109124
ctx.logger.error(ctx.error)

apps/backend/src/modules/openapi/openapi.ts

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ export class OpenAPI {
112112
},
113113
{
114114
params: t.Object({ baseName: t.String(), tableName: t.String() }),
115+
detail: {
116+
tags: ["Doc"],
117+
summary: "Get OpenAPI documentation for a table",
118+
description: "Get OpenAPI documentation for a table",
119+
},
115120
},
116121
)
117122
.group("/records", (app) => {
@@ -156,7 +161,14 @@ export class OpenAPI {
156161
records: result.values,
157162
}
158163
},
159-
{ params: t.Object({ baseName: t.String(), tableName: t.String() }) },
164+
{
165+
params: t.Object({ baseName: t.String(), tableName: t.String() }),
166+
detail: {
167+
tags: ["Record"],
168+
summary: "Get records",
169+
description: "Get records",
170+
},
171+
},
160172
)
161173
.get(
162174
"/:recordId",
@@ -169,7 +181,14 @@ export class OpenAPI {
169181
data: result,
170182
}
171183
},
172-
{ params: t.Object({ baseName: t.String(), tableName: t.String(), recordId: t.String() }) },
184+
{
185+
params: t.Object({ baseName: t.String(), tableName: t.String(), recordId: t.String() }),
186+
detail: {
187+
tags: ["Record"],
188+
summary: "Get record by id",
189+
description: "Get record by id",
190+
},
191+
},
173192
)
174193
.post(
175194
"/",
@@ -182,6 +201,11 @@ export class OpenAPI {
182201
{
183202
params: t.Object({ baseName: t.String(), tableName: t.String() }),
184203
body: t.Object({ values: t.Record(t.String(), t.Any()) }),
204+
detail: {
205+
tags: ["Record"],
206+
summary: "Create record",
207+
description: "Create record",
208+
},
185209
},
186210
)
187211
.post(
@@ -195,6 +219,11 @@ export class OpenAPI {
195219
{
196220
params: t.Object({ baseName: t.String(), tableName: t.String() }),
197221
body: t.Object({ records: t.Array(t.Object({ id: t.Optional(t.String()), values: t.Any() })) }),
222+
detail: {
223+
tags: ["Record"],
224+
summary: "Create records",
225+
description: "Create records",
226+
},
198227
},
199228
)
200229
.patch(
@@ -215,6 +244,11 @@ export class OpenAPI {
215244
{
216245
params: t.Object({ baseName: t.String(), tableName: t.String(), recordId: t.String() }),
217246
body: t.Object({ values: t.Record(t.String(), t.Any()) }),
247+
detail: {
248+
tags: ["Record"],
249+
summary: "Update record by id",
250+
description: "Update record by id",
251+
},
218252
},
219253
)
220254
.patch(
@@ -239,6 +273,11 @@ export class OpenAPI {
239273
filter: t.Any(),
240274
values: t.Record(t.String(), t.Any()),
241275
}),
276+
detail: {
277+
tags: ["Record"],
278+
summary: "Update records",
279+
description: "Update records",
280+
},
242281
},
243282
)
244283
.post(
@@ -249,7 +288,14 @@ export class OpenAPI {
249288
this.commandBus.execute(new DuplicateRecordCommand({ baseName, tableName, id: ctx.params.recordId })),
250289
)
251290
},
252-
{ params: t.Object({ baseName: t.String(), tableName: t.String(), recordId: t.String() }) },
291+
{
292+
params: t.Object({ baseName: t.String(), tableName: t.String(), recordId: t.String() }),
293+
detail: {
294+
tags: ["Record"],
295+
summary: "Duplicate record by id",
296+
description: "Duplicate record by id",
297+
},
298+
},
253299
)
254300
.post(
255301
"/records/duplicate",
@@ -269,6 +315,11 @@ export class OpenAPI {
269315
{
270316
params: t.Object({ baseName: t.String(), tableName: t.String() }),
271317
body: t.Object({ filter: t.Any() }),
318+
detail: {
319+
tags: ["Record"],
320+
summary: "Duplicate records",
321+
description: "Duplicate records",
322+
},
272323
},
273324
)
274325
.delete(
@@ -279,7 +330,14 @@ export class OpenAPI {
279330
this.commandBus.execute(new DeleteRecordCommand({ baseName, tableName, id: ctx.params.recordId })),
280331
)
281332
},
282-
{ params: t.Object({ baseName: t.String(), tableName: t.String(), recordId: t.String() }) },
333+
{
334+
params: t.Object({ baseName: t.String(), tableName: t.String(), recordId: t.String() }),
335+
detail: {
336+
tags: ["Record"],
337+
summary: "Delete record by id",
338+
description: "Delete record by id",
339+
},
340+
},
283341
)
284342
.delete(
285343
"/",
@@ -299,6 +357,11 @@ export class OpenAPI {
299357
{
300358
params: t.Object({ baseName: t.String(), tableName: t.String() }),
301359
body: t.Object({ filter: t.Any() }),
360+
detail: {
361+
tags: ["Record"],
362+
summary: "Delete records",
363+
description: "Delete records",
364+
},
302365
},
303366
)
304367
})

0 commit comments

Comments
 (0)