@byterings-dev/contracts 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/api-keys.d.ts +54 -0
- package/dist/api-keys.js +23 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/audit.d.ts +21 -0
- package/dist/audit.js +22 -0
- package/dist/audit.js.map +1 -0
- package/dist/auth.d.ts +76 -0
- package/dist/auth.js +39 -0
- package/dist/auth.js.map +1 -0
- package/dist/common.d.ts +27 -0
- package/dist/common.js +25 -0
- package/dist/common.js.map +1 -0
- package/dist/config.d.ts +241 -0
- package/dist/config.js +73 -0
- package/dist/config.js.map +1 -0
- package/dist/entities.d.ts +140 -0
- package/dist/entities.js +62 -0
- package/dist/entities.js.map +1 -0
- package/dist/fields.d.ts +233 -0
- package/dist/fields.js +445 -0
- package/dist/fields.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +48 -0
- package/dist/media.js +46 -0
- package/dist/media.js.map +1 -0
- package/dist/members.d.ts +40 -0
- package/dist/members.js +26 -0
- package/dist/members.js.map +1 -0
- package/dist/openapi.d.ts +122 -0
- package/dist/openapi.js +958 -0
- package/dist/openapi.js.map +1 -0
- package/dist/pagination.d.ts +25 -0
- package/dist/pagination.js +30 -0
- package/dist/pagination.js.map +1 -0
- package/dist/permissions.d.ts +46 -0
- package/dist/permissions.js +73 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugins.d.ts +204 -0
- package/dist/plugins.js +108 -0
- package/dist/plugins.js.map +1 -0
- package/dist/records.d.ts +50 -0
- package/dist/records.js +47 -0
- package/dist/records.js.map +1 -0
- package/dist/release.d.ts +75 -0
- package/dist/release.js +32 -0
- package/dist/release.js.map +1 -0
- package/dist/templates.d.ts +142 -0
- package/dist/templates.js +79 -0
- package/dist/templates.js.map +1 -0
- package/dist/tenants.d.ts +52 -0
- package/dist/tenants.js +47 -0
- package/dist/tenants.js.map +1 -0
- package/package.json +29 -3
- package/README.md +0 -3
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,958 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_OPERATIONS = void 0;
|
|
4
|
+
exports.buildOpenApiDocument = buildOpenApiDocument;
|
|
5
|
+
exports.fieldValueJsonSchema = fieldValueJsonSchema;
|
|
6
|
+
exports.buildTenantOpenApiDocument = buildTenantOpenApiDocument;
|
|
7
|
+
/**
|
|
8
|
+
* OpenAPI 3.1 documents generated from the shared Zod contracts (ADR-007).
|
|
9
|
+
*
|
|
10
|
+
* - `API_OPERATIONS` is the single registry of every REST operation. A
|
|
11
|
+
* contract test in the API fails when a route is missing here.
|
|
12
|
+
* - `buildOpenApiDocument()` renders the platform-wide specification.
|
|
13
|
+
* - `buildTenantOpenApiDocument()` adds typed schemas and paths for one
|
|
14
|
+
* tenant's entities, derived from their field definitions.
|
|
15
|
+
*/
|
|
16
|
+
const zod_1 = require("zod");
|
|
17
|
+
const api_keys_1 = require("./api-keys");
|
|
18
|
+
const audit_1 = require("./audit");
|
|
19
|
+
const auth_1 = require("./auth");
|
|
20
|
+
const common_1 = require("./common");
|
|
21
|
+
const config_1 = require("./config");
|
|
22
|
+
const entities_1 = require("./entities");
|
|
23
|
+
const fields_1 = require("./fields");
|
|
24
|
+
const media_1 = require("./media");
|
|
25
|
+
const members_1 = require("./members");
|
|
26
|
+
const plugins_1 = require("./plugins");
|
|
27
|
+
const templates_1 = require("./templates");
|
|
28
|
+
const pagination_1 = require("./pagination");
|
|
29
|
+
const records_1 = require("./records");
|
|
30
|
+
const tenants_1 = require("./tenants");
|
|
31
|
+
const data = (schema) => zod_1.z.object({ data: schema });
|
|
32
|
+
const page = (schema) => zod_1.z.object({ data: zod_1.z.array(schema), meta: pagination_1.pageMetaSchema });
|
|
33
|
+
const pageParams = [
|
|
34
|
+
{ name: 'page', schema: { type: 'integer', minimum: 1, default: 1 } },
|
|
35
|
+
{ name: 'pageSize', schema: { type: 'integer', minimum: 1, maximum: 100, default: 20 } },
|
|
36
|
+
];
|
|
37
|
+
const recordListParams = [
|
|
38
|
+
...pageParams,
|
|
39
|
+
{
|
|
40
|
+
name: 'sort',
|
|
41
|
+
schema: { type: 'string' },
|
|
42
|
+
description: 'Comma-separated field keys; prefix "-" for descending, e.g. -price,name',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'fields',
|
|
46
|
+
schema: { type: 'string' },
|
|
47
|
+
description: 'Comma-separated field keys to return',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'search',
|
|
51
|
+
schema: { type: 'string' },
|
|
52
|
+
description: 'Case-insensitive match on text fields',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'expand',
|
|
56
|
+
schema: { type: 'string' },
|
|
57
|
+
description: 'Comma-separated relation fields to expand (depth 1)',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'filter',
|
|
61
|
+
schema: { type: 'object', additionalProperties: true },
|
|
62
|
+
description: 'Deep-object filters: filter[field]=value or filter[field][op]=value with op in eq, ne, gt, gte, lt, lte, in, contains, startsWith, isNull',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'deleted',
|
|
66
|
+
schema: { type: 'string', enum: ['true', 'false'] },
|
|
67
|
+
description: 'Admins: list soft-deleted records',
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
/** Every REST operation of API v1. Keep in sync with the controllers. */
|
|
71
|
+
exports.API_OPERATIONS = [
|
|
72
|
+
// Health and docs
|
|
73
|
+
{
|
|
74
|
+
method: 'get',
|
|
75
|
+
path: '/health',
|
|
76
|
+
tag: 'System',
|
|
77
|
+
summary: 'Liveness check',
|
|
78
|
+
auth: 'public',
|
|
79
|
+
response: common_1.healthResponseSchema,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
method: 'get',
|
|
83
|
+
path: '/health/ready',
|
|
84
|
+
tag: 'System',
|
|
85
|
+
summary: 'Readiness check (database)',
|
|
86
|
+
auth: 'public',
|
|
87
|
+
response: common_1.healthResponseSchema,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
method: 'get',
|
|
91
|
+
path: '/openapi.json',
|
|
92
|
+
tag: 'System',
|
|
93
|
+
summary: 'This OpenAPI document',
|
|
94
|
+
auth: 'public',
|
|
95
|
+
contentType: 'application/json',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
method: 'get',
|
|
99
|
+
path: '/openapi/tenant.json',
|
|
100
|
+
tag: 'System',
|
|
101
|
+
summary: 'OpenAPI document including the current tenant’s entities',
|
|
102
|
+
auth: 'any',
|
|
103
|
+
permission: 'metadata:read',
|
|
104
|
+
contentType: 'application/json',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
method: 'get',
|
|
108
|
+
path: '/docs',
|
|
109
|
+
tag: 'System',
|
|
110
|
+
summary: 'Interactive API documentation',
|
|
111
|
+
auth: 'public',
|
|
112
|
+
contentType: 'text/html',
|
|
113
|
+
},
|
|
114
|
+
// Setup and authentication
|
|
115
|
+
{
|
|
116
|
+
method: 'get',
|
|
117
|
+
path: '/setup/status',
|
|
118
|
+
tag: 'Setup',
|
|
119
|
+
summary: 'Whether the installation is initialized',
|
|
120
|
+
auth: 'public',
|
|
121
|
+
response: data(auth_1.setupStatusSchema),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
method: 'post',
|
|
125
|
+
path: '/setup',
|
|
126
|
+
tag: 'Setup',
|
|
127
|
+
summary: 'First-run setup: create the first tenant and owner',
|
|
128
|
+
auth: 'public',
|
|
129
|
+
body: auth_1.setupRequestSchema,
|
|
130
|
+
response: data(auth_1.sessionSchema),
|
|
131
|
+
status: 201,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
method: 'post',
|
|
135
|
+
path: '/auth/login',
|
|
136
|
+
tag: 'Auth',
|
|
137
|
+
summary: 'Sign in (sets a session cookie)',
|
|
138
|
+
auth: 'public',
|
|
139
|
+
body: auth_1.loginRequestSchema,
|
|
140
|
+
response: data(auth_1.sessionSchema),
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
method: 'get',
|
|
144
|
+
path: '/auth/session',
|
|
145
|
+
tag: 'Auth',
|
|
146
|
+
summary: 'Current session',
|
|
147
|
+
auth: 'user',
|
|
148
|
+
response: data(auth_1.sessionSchema),
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
method: 'post',
|
|
152
|
+
path: '/auth/logout',
|
|
153
|
+
tag: 'Auth',
|
|
154
|
+
summary: 'Sign out',
|
|
155
|
+
auth: 'user',
|
|
156
|
+
status: 204,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
method: 'post',
|
|
160
|
+
path: '/auth/switch-tenant',
|
|
161
|
+
tag: 'Auth',
|
|
162
|
+
summary: 'Switch the active tenant',
|
|
163
|
+
auth: 'user',
|
|
164
|
+
body: auth_1.switchTenantRequestSchema,
|
|
165
|
+
response: data(auth_1.sessionSchema),
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
method: 'post',
|
|
169
|
+
path: '/auth/password',
|
|
170
|
+
tag: 'Auth',
|
|
171
|
+
summary: 'Change own password',
|
|
172
|
+
auth: 'user',
|
|
173
|
+
body: auth_1.changePasswordRequestSchema,
|
|
174
|
+
status: 204,
|
|
175
|
+
},
|
|
176
|
+
// Tenants
|
|
177
|
+
{
|
|
178
|
+
method: 'get',
|
|
179
|
+
path: '/tenant',
|
|
180
|
+
tag: 'Tenant',
|
|
181
|
+
summary: 'Current tenant',
|
|
182
|
+
auth: 'any',
|
|
183
|
+
permission: 'metadata:read',
|
|
184
|
+
response: data(tenants_1.tenantSchema),
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
method: 'patch',
|
|
188
|
+
path: '/tenant',
|
|
189
|
+
tag: 'Tenant',
|
|
190
|
+
summary: 'Rename the current tenant',
|
|
191
|
+
auth: 'any',
|
|
192
|
+
permission: 'tenant:manage',
|
|
193
|
+
body: tenants_1.updateTenantRequestSchema,
|
|
194
|
+
response: data(tenants_1.tenantSchema),
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
method: 'get',
|
|
198
|
+
path: '/platform/tenants',
|
|
199
|
+
tag: 'Platform',
|
|
200
|
+
summary: 'List all tenants',
|
|
201
|
+
auth: 'platformAdmin',
|
|
202
|
+
response: data(zod_1.z.array(tenants_1.tenantSchema)),
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
method: 'post',
|
|
206
|
+
path: '/platform/tenants',
|
|
207
|
+
tag: 'Platform',
|
|
208
|
+
summary: 'Provision a tenant and its owner',
|
|
209
|
+
auth: 'platformAdmin',
|
|
210
|
+
body: tenants_1.createTenantRequestSchema,
|
|
211
|
+
response: data(tenants_1.tenantSchema),
|
|
212
|
+
status: 201,
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
method: 'patch',
|
|
216
|
+
path: '/platform/tenants/{id}/status',
|
|
217
|
+
tag: 'Platform',
|
|
218
|
+
summary: 'Suspend or reactivate a tenant',
|
|
219
|
+
auth: 'platformAdmin',
|
|
220
|
+
body: tenants_1.updateTenantStatusRequestSchema,
|
|
221
|
+
response: data(tenants_1.tenantSchema),
|
|
222
|
+
},
|
|
223
|
+
// Members, API keys, audit
|
|
224
|
+
{
|
|
225
|
+
method: 'get',
|
|
226
|
+
path: '/admin/members',
|
|
227
|
+
tag: 'Members',
|
|
228
|
+
summary: 'List members',
|
|
229
|
+
auth: 'user',
|
|
230
|
+
permission: 'members:manage',
|
|
231
|
+
response: data(zod_1.z.array(members_1.memberSchema)),
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
method: 'post',
|
|
235
|
+
path: '/admin/members',
|
|
236
|
+
tag: 'Members',
|
|
237
|
+
summary: 'Add a member',
|
|
238
|
+
auth: 'user',
|
|
239
|
+
permission: 'members:manage',
|
|
240
|
+
body: members_1.addMemberRequestSchema,
|
|
241
|
+
response: data(members_1.memberSchema),
|
|
242
|
+
status: 201,
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
method: 'patch',
|
|
246
|
+
path: '/admin/members/{id}',
|
|
247
|
+
tag: 'Members',
|
|
248
|
+
summary: 'Change a member’s role',
|
|
249
|
+
auth: 'user',
|
|
250
|
+
permission: 'members:manage',
|
|
251
|
+
body: members_1.updateMemberRequestSchema,
|
|
252
|
+
response: data(members_1.memberSchema),
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
method: 'delete',
|
|
256
|
+
path: '/admin/members/{id}',
|
|
257
|
+
tag: 'Members',
|
|
258
|
+
summary: 'Remove a member',
|
|
259
|
+
auth: 'user',
|
|
260
|
+
permission: 'members:manage',
|
|
261
|
+
status: 204,
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
method: 'get',
|
|
265
|
+
path: '/admin/api-keys',
|
|
266
|
+
tag: 'API keys',
|
|
267
|
+
summary: 'List API keys',
|
|
268
|
+
auth: 'user',
|
|
269
|
+
permission: 'apikeys:manage',
|
|
270
|
+
response: data(zod_1.z.array(api_keys_1.apiKeySchema)),
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
method: 'post',
|
|
274
|
+
path: '/admin/api-keys',
|
|
275
|
+
tag: 'API keys',
|
|
276
|
+
summary: 'Create an API key (secret returned once)',
|
|
277
|
+
auth: 'user',
|
|
278
|
+
permission: 'apikeys:manage',
|
|
279
|
+
body: api_keys_1.createApiKeyRequestSchema,
|
|
280
|
+
response: data(api_keys_1.createdApiKeySchema),
|
|
281
|
+
status: 201,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
method: 'delete',
|
|
285
|
+
path: '/admin/api-keys/{id}',
|
|
286
|
+
tag: 'API keys',
|
|
287
|
+
summary: 'Revoke an API key',
|
|
288
|
+
auth: 'user',
|
|
289
|
+
permission: 'apikeys:manage',
|
|
290
|
+
status: 204,
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
method: 'get',
|
|
294
|
+
path: '/admin/audit-events',
|
|
295
|
+
tag: 'Audit',
|
|
296
|
+
summary: 'List audit events',
|
|
297
|
+
auth: 'any',
|
|
298
|
+
permission: 'audit:read',
|
|
299
|
+
query: [
|
|
300
|
+
...pageParams,
|
|
301
|
+
{ name: 'action', schema: { type: 'string' } },
|
|
302
|
+
{ name: 'targetType', schema: { type: 'string' } },
|
|
303
|
+
{ name: 'targetId', schema: { type: 'string' } },
|
|
304
|
+
],
|
|
305
|
+
response: page(audit_1.auditEventSchema),
|
|
306
|
+
},
|
|
307
|
+
// Metadata
|
|
308
|
+
{
|
|
309
|
+
method: 'get',
|
|
310
|
+
path: '/admin/field-types',
|
|
311
|
+
tag: 'Metadata',
|
|
312
|
+
summary: 'Field type registry',
|
|
313
|
+
auth: 'any',
|
|
314
|
+
permission: 'metadata:read',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
method: 'get',
|
|
318
|
+
path: '/admin/entities',
|
|
319
|
+
tag: 'Metadata',
|
|
320
|
+
summary: 'List entities',
|
|
321
|
+
auth: 'any',
|
|
322
|
+
permission: 'metadata:read',
|
|
323
|
+
response: data(zod_1.z.array(entities_1.entitySchema)),
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
method: 'post',
|
|
327
|
+
path: '/admin/entities',
|
|
328
|
+
tag: 'Metadata',
|
|
329
|
+
summary: 'Create an entity',
|
|
330
|
+
auth: 'any',
|
|
331
|
+
permission: 'metadata:write',
|
|
332
|
+
body: entities_1.createEntityRequestSchema,
|
|
333
|
+
response: data(entities_1.entitySchema),
|
|
334
|
+
status: 201,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
method: 'get',
|
|
338
|
+
path: '/admin/entities/{entityId}',
|
|
339
|
+
tag: 'Metadata',
|
|
340
|
+
summary: 'Get an entity',
|
|
341
|
+
auth: 'any',
|
|
342
|
+
permission: 'metadata:read',
|
|
343
|
+
response: data(entities_1.entitySchema),
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
method: 'patch',
|
|
347
|
+
path: '/admin/entities/{entityId}',
|
|
348
|
+
tag: 'Metadata',
|
|
349
|
+
summary: 'Update entity settings',
|
|
350
|
+
auth: 'any',
|
|
351
|
+
permission: 'metadata:write',
|
|
352
|
+
body: entities_1.updateEntityRequestSchema,
|
|
353
|
+
response: data(entities_1.entitySchema),
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
method: 'delete',
|
|
357
|
+
path: '/admin/entities/{entityId}',
|
|
358
|
+
tag: 'Metadata',
|
|
359
|
+
summary: 'Delete an entity without live records',
|
|
360
|
+
auth: 'any',
|
|
361
|
+
permission: 'metadata:write',
|
|
362
|
+
status: 204,
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
method: 'get',
|
|
366
|
+
path: '/admin/entities/{entityId}/versions',
|
|
367
|
+
tag: 'Metadata',
|
|
368
|
+
summary: 'Metadata version history',
|
|
369
|
+
auth: 'any',
|
|
370
|
+
permission: 'metadata:read',
|
|
371
|
+
response: data(zod_1.z.array(entities_1.metadataVersionSchema)),
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
method: 'post',
|
|
375
|
+
path: '/admin/entities/{entityId}/fields',
|
|
376
|
+
tag: 'Metadata',
|
|
377
|
+
summary: 'Add a field',
|
|
378
|
+
auth: 'any',
|
|
379
|
+
permission: 'metadata:write',
|
|
380
|
+
body: fields_1.createFieldRequestSchema,
|
|
381
|
+
response: data(entities_1.entitySchema),
|
|
382
|
+
status: 201,
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
method: 'patch',
|
|
386
|
+
path: '/admin/entities/{entityId}/fields/{fieldId}',
|
|
387
|
+
tag: 'Metadata',
|
|
388
|
+
summary: 'Update a field',
|
|
389
|
+
auth: 'any',
|
|
390
|
+
permission: 'metadata:write',
|
|
391
|
+
body: fields_1.updateFieldRequestSchema,
|
|
392
|
+
response: data(entities_1.entitySchema),
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
method: 'delete',
|
|
396
|
+
path: '/admin/entities/{entityId}/fields/{fieldId}',
|
|
397
|
+
tag: 'Metadata',
|
|
398
|
+
summary: 'Delete a field and its values',
|
|
399
|
+
auth: 'any',
|
|
400
|
+
permission: 'metadata:write',
|
|
401
|
+
response: data(entities_1.entitySchema),
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
method: 'post',
|
|
405
|
+
path: '/admin/entities/{entityId}/fields/reorder',
|
|
406
|
+
tag: 'Metadata',
|
|
407
|
+
summary: 'Reorder fields',
|
|
408
|
+
auth: 'any',
|
|
409
|
+
permission: 'metadata:write',
|
|
410
|
+
body: fields_1.reorderFieldsRequestSchema,
|
|
411
|
+
response: data(entities_1.entitySchema),
|
|
412
|
+
},
|
|
413
|
+
// Configuration as code (ADR-010)
|
|
414
|
+
{
|
|
415
|
+
method: 'get',
|
|
416
|
+
path: '/admin/config/export',
|
|
417
|
+
tag: 'Config',
|
|
418
|
+
summary: 'Export metadata as a portable document',
|
|
419
|
+
auth: 'any',
|
|
420
|
+
permission: 'metadata:read',
|
|
421
|
+
response: data(config_1.configDocumentSchema),
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
method: 'post',
|
|
425
|
+
path: '/admin/config/diff',
|
|
426
|
+
tag: 'Config',
|
|
427
|
+
summary: 'Plan changes needed to reach a document (read-only)',
|
|
428
|
+
auth: 'any',
|
|
429
|
+
permission: 'metadata:write',
|
|
430
|
+
query: [
|
|
431
|
+
{
|
|
432
|
+
name: 'prune',
|
|
433
|
+
schema: { type: 'string', enum: ['true', 'false'] },
|
|
434
|
+
description: 'Include deletions of undeclared entities and fields',
|
|
435
|
+
},
|
|
436
|
+
],
|
|
437
|
+
body: config_1.configDocumentSchema,
|
|
438
|
+
response: data(config_1.configPlanSchema),
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
method: 'post',
|
|
442
|
+
path: '/admin/config/apply',
|
|
443
|
+
tag: 'Config',
|
|
444
|
+
summary: 'Apply a document atomically',
|
|
445
|
+
auth: 'any',
|
|
446
|
+
permission: 'metadata:write',
|
|
447
|
+
body: config_1.configApplyRequestSchema,
|
|
448
|
+
response: data(config_1.configPlanSchema),
|
|
449
|
+
},
|
|
450
|
+
// Records
|
|
451
|
+
{
|
|
452
|
+
method: 'get',
|
|
453
|
+
path: '/entities/{entityKey}/records',
|
|
454
|
+
tag: 'Records',
|
|
455
|
+
summary: 'List records',
|
|
456
|
+
auth: 'any',
|
|
457
|
+
permission: 'records:read',
|
|
458
|
+
query: recordListParams,
|
|
459
|
+
response: page(records_1.recordSchema),
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
method: 'post',
|
|
463
|
+
path: '/entities/{entityKey}/records',
|
|
464
|
+
tag: 'Records',
|
|
465
|
+
summary: 'Create a record',
|
|
466
|
+
auth: 'any',
|
|
467
|
+
permission: 'records:write',
|
|
468
|
+
body: records_1.createRecordRequestSchema,
|
|
469
|
+
response: data(records_1.recordSchema),
|
|
470
|
+
status: 201,
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
method: 'get',
|
|
474
|
+
path: '/entities/{entityKey}/records/{id}',
|
|
475
|
+
tag: 'Records',
|
|
476
|
+
summary: 'Get a record',
|
|
477
|
+
auth: 'any',
|
|
478
|
+
permission: 'records:read',
|
|
479
|
+
query: [recordListParams[3], recordListParams[5]],
|
|
480
|
+
response: data(records_1.recordSchema),
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
method: 'patch',
|
|
484
|
+
path: '/entities/{entityKey}/records/{id}',
|
|
485
|
+
tag: 'Records',
|
|
486
|
+
summary: 'Update a record (optionally with version check)',
|
|
487
|
+
auth: 'any',
|
|
488
|
+
permission: 'records:write',
|
|
489
|
+
body: records_1.updateRecordRequestSchema,
|
|
490
|
+
response: data(records_1.recordSchema),
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
method: 'delete',
|
|
494
|
+
path: '/entities/{entityKey}/records/{id}',
|
|
495
|
+
tag: 'Records',
|
|
496
|
+
summary: 'Move a record to the trash',
|
|
497
|
+
auth: 'any',
|
|
498
|
+
permission: 'records:write',
|
|
499
|
+
status: 204,
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
method: 'post',
|
|
503
|
+
path: '/entities/{entityKey}/records/{id}/restore',
|
|
504
|
+
tag: 'Records',
|
|
505
|
+
summary: 'Restore a deleted record (admins)',
|
|
506
|
+
auth: 'any',
|
|
507
|
+
permission: 'records:write',
|
|
508
|
+
response: data(records_1.recordSchema),
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
method: 'delete',
|
|
512
|
+
path: '/entities/{entityKey}/records/{id}/permanent',
|
|
513
|
+
tag: 'Records',
|
|
514
|
+
summary: 'Permanently delete a trashed record (admins)',
|
|
515
|
+
auth: 'any',
|
|
516
|
+
permission: 'records:write',
|
|
517
|
+
status: 204,
|
|
518
|
+
},
|
|
519
|
+
// Media (ADR-023)
|
|
520
|
+
{
|
|
521
|
+
method: 'post',
|
|
522
|
+
path: '/media',
|
|
523
|
+
tag: 'Media',
|
|
524
|
+
summary: 'Upload a file (multipart/form-data: file, alt)',
|
|
525
|
+
auth: 'any',
|
|
526
|
+
permission: 'media:write',
|
|
527
|
+
response: data(media_1.mediaSchema),
|
|
528
|
+
status: 201,
|
|
529
|
+
contentType: 'application/json',
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
method: 'get',
|
|
533
|
+
path: '/media',
|
|
534
|
+
tag: 'Media',
|
|
535
|
+
summary: 'List media',
|
|
536
|
+
auth: 'any',
|
|
537
|
+
permission: 'media:read',
|
|
538
|
+
query: [
|
|
539
|
+
...pageParams,
|
|
540
|
+
{ name: 'kind', schema: { type: 'string', enum: ['image', 'video', 'audio', 'document'] } },
|
|
541
|
+
{ name: 'search', schema: { type: 'string' } },
|
|
542
|
+
],
|
|
543
|
+
response: page(media_1.mediaSchema),
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
method: 'get',
|
|
547
|
+
path: '/media/{id}',
|
|
548
|
+
tag: 'Media',
|
|
549
|
+
summary: 'Get media metadata',
|
|
550
|
+
auth: 'any',
|
|
551
|
+
permission: 'media:read',
|
|
552
|
+
response: data(media_1.mediaSchema),
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
method: 'get',
|
|
556
|
+
path: '/media/{id}/file',
|
|
557
|
+
tag: 'Media',
|
|
558
|
+
summary: 'Download the file',
|
|
559
|
+
auth: 'any',
|
|
560
|
+
permission: 'media:read',
|
|
561
|
+
contentType: 'application/octet-stream',
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
method: 'patch',
|
|
565
|
+
path: '/media/{id}',
|
|
566
|
+
tag: 'Media',
|
|
567
|
+
summary: 'Update alt text or file name',
|
|
568
|
+
auth: 'any',
|
|
569
|
+
permission: 'media:write',
|
|
570
|
+
body: media_1.updateMediaRequestSchema,
|
|
571
|
+
response: data(media_1.mediaSchema),
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
method: 'delete',
|
|
575
|
+
path: '/media/{id}',
|
|
576
|
+
tag: 'Media',
|
|
577
|
+
summary: 'Delete media',
|
|
578
|
+
auth: 'any',
|
|
579
|
+
permission: 'media:write',
|
|
580
|
+
status: 204,
|
|
581
|
+
},
|
|
582
|
+
// Templates (ADR-009)
|
|
583
|
+
{
|
|
584
|
+
method: 'get',
|
|
585
|
+
path: '/admin/templates',
|
|
586
|
+
tag: 'Templates',
|
|
587
|
+
summary: 'Available and installed templates',
|
|
588
|
+
auth: 'any',
|
|
589
|
+
permission: 'templates:manage',
|
|
590
|
+
response: data(zod_1.z.array(templates_1.templateInfoSchema)),
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
method: 'post',
|
|
594
|
+
path: '/admin/templates/{templateId}/install',
|
|
595
|
+
tag: 'Templates',
|
|
596
|
+
summary: 'Install a template',
|
|
597
|
+
auth: 'any',
|
|
598
|
+
permission: 'templates:manage',
|
|
599
|
+
body: templates_1.installTemplateRequestSchema,
|
|
600
|
+
response: data(templates_1.templateInfoSchema),
|
|
601
|
+
status: 201,
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
method: 'get',
|
|
605
|
+
path: '/admin/templates/{templateId}/upgrade-plan',
|
|
606
|
+
tag: 'Templates',
|
|
607
|
+
summary: 'Preview an upgrade to the available version',
|
|
608
|
+
auth: 'any',
|
|
609
|
+
permission: 'templates:manage',
|
|
610
|
+
response: data(templates_1.upgradePlanSchema),
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
method: 'post',
|
|
614
|
+
path: '/admin/templates/{templateId}/upgrade',
|
|
615
|
+
tag: 'Templates',
|
|
616
|
+
summary: 'Upgrade a template (keeps tenant customizations)',
|
|
617
|
+
auth: 'any',
|
|
618
|
+
permission: 'templates:manage',
|
|
619
|
+
body: templates_1.upgradeTemplateRequestSchema,
|
|
620
|
+
response: data(templates_1.upgradePlanSchema),
|
|
621
|
+
},
|
|
622
|
+
{
|
|
623
|
+
method: 'get',
|
|
624
|
+
path: '/admin/templates/{templateId}/upgrades',
|
|
625
|
+
tag: 'Templates',
|
|
626
|
+
summary: 'Upgrade history, including failed attempts',
|
|
627
|
+
auth: 'any',
|
|
628
|
+
permission: 'templates:manage',
|
|
629
|
+
response: data(zod_1.z.array(templates_1.templateUpgradeSchema)),
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
method: 'get',
|
|
633
|
+
path: '/admin/usage',
|
|
634
|
+
tag: 'Tenant',
|
|
635
|
+
summary: 'Usage and quota limits of the current tenant',
|
|
636
|
+
auth: 'any',
|
|
637
|
+
permission: 'audit:read',
|
|
638
|
+
},
|
|
639
|
+
// Plugins (trusted, server-installed)
|
|
640
|
+
{
|
|
641
|
+
method: 'get',
|
|
642
|
+
path: '/admin/plugins',
|
|
643
|
+
tag: 'Plugins',
|
|
644
|
+
summary: 'Installed plugins and their state for this tenant',
|
|
645
|
+
auth: 'any',
|
|
646
|
+
permission: 'templates:manage',
|
|
647
|
+
response: data(zod_1.z.array(plugins_1.pluginInfoSchema)),
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
method: 'post',
|
|
651
|
+
path: '/admin/plugins/{pluginId}/enable',
|
|
652
|
+
tag: 'Plugins',
|
|
653
|
+
summary: 'Enable a plugin for this tenant',
|
|
654
|
+
auth: 'any',
|
|
655
|
+
permission: 'templates:manage',
|
|
656
|
+
response: data(plugins_1.pluginInfoSchema),
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
method: 'post',
|
|
660
|
+
path: '/admin/plugins/{pluginId}/disable',
|
|
661
|
+
tag: 'Plugins',
|
|
662
|
+
summary: 'Disable a plugin for this tenant',
|
|
663
|
+
auth: 'any',
|
|
664
|
+
permission: 'templates:manage',
|
|
665
|
+
response: data(plugins_1.pluginInfoSchema),
|
|
666
|
+
},
|
|
667
|
+
// Public content API (ADR-025)
|
|
668
|
+
{
|
|
669
|
+
method: 'get',
|
|
670
|
+
path: '/public/{tenantSlug}/entities/{entityKey}/records',
|
|
671
|
+
tag: 'Public',
|
|
672
|
+
summary: 'List published public records',
|
|
673
|
+
auth: 'public',
|
|
674
|
+
query: recordListParams.filter((p) => p.name !== 'deleted'),
|
|
675
|
+
response: page(records_1.recordSchema),
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
method: 'get',
|
|
679
|
+
path: '/public/{tenantSlug}/entities/{entityKey}/records/{id}',
|
|
680
|
+
tag: 'Public',
|
|
681
|
+
summary: 'Get a published public record',
|
|
682
|
+
auth: 'public',
|
|
683
|
+
query: [recordListParams[3], recordListParams[5]],
|
|
684
|
+
response: data(records_1.recordSchema),
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
method: 'get',
|
|
688
|
+
path: '/public/{tenantSlug}/media/{id}/file',
|
|
689
|
+
tag: 'Public',
|
|
690
|
+
summary: 'Download a file referenced by published public content',
|
|
691
|
+
auth: 'public',
|
|
692
|
+
contentType: 'application/octet-stream',
|
|
693
|
+
},
|
|
694
|
+
];
|
|
695
|
+
// ---------------------------------------------------------------------------
|
|
696
|
+
function jsonSchema(schema, io) {
|
|
697
|
+
const { $schema: _ignored, ...rest } = zod_1.z.toJSONSchema(schema, {
|
|
698
|
+
io,
|
|
699
|
+
unrepresentable: 'any',
|
|
700
|
+
});
|
|
701
|
+
return rest;
|
|
702
|
+
}
|
|
703
|
+
const ERROR_RESPONSES = {
|
|
704
|
+
'400': 'Bad request (invalid filter, sort or parameters)',
|
|
705
|
+
'401': 'Authentication required or invalid credentials',
|
|
706
|
+
'403': 'Forbidden (missing permission, CSRF token or tenant access)',
|
|
707
|
+
'404': 'Not found (also returned for resources of other tenants)',
|
|
708
|
+
'409': 'Conflict (uniqueness, version or state)',
|
|
709
|
+
'422': 'Validation failed (details list each invalid path)',
|
|
710
|
+
'429': 'Rate limit exceeded',
|
|
711
|
+
};
|
|
712
|
+
function security(auth) {
|
|
713
|
+
if (auth === 'public')
|
|
714
|
+
return [];
|
|
715
|
+
if (auth === 'any')
|
|
716
|
+
return [{ sessionCookie: [], csrfToken: [] }, { apiKey: [] }];
|
|
717
|
+
return [{ sessionCookie: [], csrfToken: [] }];
|
|
718
|
+
}
|
|
719
|
+
function operationObject(op, overrides = {}) {
|
|
720
|
+
const pathParams = [...op.path.matchAll(/\{(\w+)\}/g)].map((m) => m[1]);
|
|
721
|
+
const status = String(op.status ?? 200);
|
|
722
|
+
const success = { description: 'Success' };
|
|
723
|
+
const responseSchema = overrides.response ?? (op.response ? jsonSchema(op.response, 'output') : undefined);
|
|
724
|
+
if (responseSchema)
|
|
725
|
+
success.content = { 'application/json': { schema: responseSchema } };
|
|
726
|
+
else if (op.contentType)
|
|
727
|
+
success.content = { [op.contentType]: {} };
|
|
728
|
+
const responses = { [status]: success };
|
|
729
|
+
for (const [code, description] of Object.entries(ERROR_RESPONSES)) {
|
|
730
|
+
if (op.auth === 'public' && (code === '401' || code === '403'))
|
|
731
|
+
continue;
|
|
732
|
+
responses[code] = {
|
|
733
|
+
description,
|
|
734
|
+
content: { 'application/json': { schema: { $ref: '#/components/schemas/ApiError' } } },
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
const bodySchema = overrides.body ?? (op.body ? jsonSchema(op.body, 'input') : undefined);
|
|
738
|
+
return {
|
|
739
|
+
tags: [op.tag],
|
|
740
|
+
summary: op.summary,
|
|
741
|
+
operationId: `${op.method}${op.path.replace(/[{}]/g, '').replace(/[^a-zA-Z0-9]+(.)?/g, (_m, c) => (c ? c.toUpperCase() : ''))}`,
|
|
742
|
+
...(op.permission ? { description: `Requires permission \`${op.permission}\`.` } : {}),
|
|
743
|
+
security: security(op.auth),
|
|
744
|
+
parameters: [
|
|
745
|
+
...pathParams.map((name) => ({
|
|
746
|
+
name,
|
|
747
|
+
in: 'path',
|
|
748
|
+
required: true,
|
|
749
|
+
schema: { type: 'string' },
|
|
750
|
+
})),
|
|
751
|
+
...(op.query ?? []).map((q) => ({
|
|
752
|
+
name: q.name,
|
|
753
|
+
in: 'query',
|
|
754
|
+
required: false,
|
|
755
|
+
schema: q.schema,
|
|
756
|
+
...(q.description ? { description: q.description } : {}),
|
|
757
|
+
...(q.name === 'filter' ? { style: 'deepObject', explode: true } : {}),
|
|
758
|
+
})),
|
|
759
|
+
],
|
|
760
|
+
...(bodySchema
|
|
761
|
+
? { requestBody: { required: true, content: { 'application/json': { schema: bodySchema } } } }
|
|
762
|
+
: {}),
|
|
763
|
+
responses,
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function baseDocument(serverUrl, version, title) {
|
|
767
|
+
return {
|
|
768
|
+
openapi: '3.1.0',
|
|
769
|
+
info: {
|
|
770
|
+
title,
|
|
771
|
+
version,
|
|
772
|
+
license: { name: 'MIT', identifier: 'MIT' },
|
|
773
|
+
description: 'REST API of the metadata-driven application platform. Errors use `{ error: { code, message, details? } }`. ' +
|
|
774
|
+
'Browser clients authenticate with the session cookie and send the CSRF token from the session in `x-csrf-token` on state-changing requests. ' +
|
|
775
|
+
'Machine clients send `Authorization: Bearer <api key>`.',
|
|
776
|
+
},
|
|
777
|
+
servers: [{ url: serverUrl }],
|
|
778
|
+
components: {
|
|
779
|
+
securitySchemes: {
|
|
780
|
+
sessionCookie: { type: 'apiKey', in: 'cookie', name: 'bcms_session' },
|
|
781
|
+
csrfToken: { type: 'apiKey', in: 'header', name: 'x-csrf-token' },
|
|
782
|
+
apiKey: { type: 'http', scheme: 'bearer', description: 'Tenant API key (bcms_...)' },
|
|
783
|
+
},
|
|
784
|
+
schemas: { ApiError: jsonSchema(common_1.apiErrorSchema, 'output') },
|
|
785
|
+
},
|
|
786
|
+
paths: {},
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
function buildOpenApiDocument(opts = {}) {
|
|
790
|
+
const doc = baseDocument(opts.serverUrl ?? '/api/v1', opts.version ?? '1.0.0', 'Platform API');
|
|
791
|
+
for (const op of exports.API_OPERATIONS) {
|
|
792
|
+
doc.paths[op.path] ??= {};
|
|
793
|
+
doc.paths[op.path][op.method] = operationObject(op);
|
|
794
|
+
}
|
|
795
|
+
return doc;
|
|
796
|
+
}
|
|
797
|
+
// ---------------------------------------------------------------------------
|
|
798
|
+
// Tenant-specific documents
|
|
799
|
+
// ---------------------------------------------------------------------------
|
|
800
|
+
/** JSON Schema of one field's value (nullable unless required). */
|
|
801
|
+
function fieldValueJsonSchema(field) {
|
|
802
|
+
const c = field.config;
|
|
803
|
+
let schema;
|
|
804
|
+
switch (field.type) {
|
|
805
|
+
case 'text': {
|
|
806
|
+
const parsed = fields_1.fieldConfigSchemas.text.parse(c);
|
|
807
|
+
schema = { type: 'string', maxLength: parsed.maxLength };
|
|
808
|
+
if (parsed.minLength !== undefined)
|
|
809
|
+
schema.minLength = parsed.minLength;
|
|
810
|
+
if (parsed.format === 'email')
|
|
811
|
+
schema.format = 'email';
|
|
812
|
+
if (parsed.format === 'url')
|
|
813
|
+
schema.format = 'uri';
|
|
814
|
+
if (parsed.format === 'slug')
|
|
815
|
+
schema.pattern = '^[a-z0-9]+(?:-[a-z0-9]+)*$';
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
case 'longtext':
|
|
819
|
+
schema = { type: 'string', maxLength: fields_1.fieldConfigSchemas.longtext.parse(c).maxLength };
|
|
820
|
+
break;
|
|
821
|
+
case 'integer': {
|
|
822
|
+
const parsed = fields_1.fieldConfigSchemas.integer.parse(c);
|
|
823
|
+
schema = {
|
|
824
|
+
type: 'integer',
|
|
825
|
+
...(parsed.min !== undefined ? { minimum: parsed.min } : {}),
|
|
826
|
+
...(parsed.max !== undefined ? { maximum: parsed.max } : {}),
|
|
827
|
+
};
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
case 'decimal':
|
|
831
|
+
schema = {
|
|
832
|
+
type: 'string',
|
|
833
|
+
pattern: '^-?\\d+(\\.\\d+)?$',
|
|
834
|
+
description: 'Decimal number as a string',
|
|
835
|
+
};
|
|
836
|
+
break;
|
|
837
|
+
case 'boolean':
|
|
838
|
+
schema = { type: 'boolean' };
|
|
839
|
+
break;
|
|
840
|
+
case 'date':
|
|
841
|
+
schema = { type: 'string', format: 'date' };
|
|
842
|
+
break;
|
|
843
|
+
case 'datetime':
|
|
844
|
+
schema = { type: 'string', format: 'date-time' };
|
|
845
|
+
break;
|
|
846
|
+
case 'select':
|
|
847
|
+
schema = {
|
|
848
|
+
type: 'string',
|
|
849
|
+
enum: fields_1.fieldConfigSchemas.select.parse(c).options.map((o) => o.value),
|
|
850
|
+
};
|
|
851
|
+
break;
|
|
852
|
+
case 'multiselect':
|
|
853
|
+
schema = {
|
|
854
|
+
type: 'array',
|
|
855
|
+
items: {
|
|
856
|
+
type: 'string',
|
|
857
|
+
enum: fields_1.fieldConfigSchemas.multiselect.parse(c).options.map((o) => o.value),
|
|
858
|
+
},
|
|
859
|
+
uniqueItems: true,
|
|
860
|
+
};
|
|
861
|
+
break;
|
|
862
|
+
case 'relation':
|
|
863
|
+
schema =
|
|
864
|
+
fields_1.fieldConfigSchemas.relation.parse(c).cardinality === 'many'
|
|
865
|
+
? { type: 'array', items: { type: 'string', format: 'uuid' }, uniqueItems: true }
|
|
866
|
+
: { type: 'string', format: 'uuid' };
|
|
867
|
+
break;
|
|
868
|
+
case 'media':
|
|
869
|
+
schema = fields_1.fieldConfigSchemas.media.parse(c).multiple
|
|
870
|
+
? { type: 'array', items: { type: 'string', format: 'uuid' }, uniqueItems: true }
|
|
871
|
+
: { type: 'string', format: 'uuid' };
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
const described = {
|
|
875
|
+
title: field.label,
|
|
876
|
+
...(field.description ? { description: field.description } : {}),
|
|
877
|
+
...schema,
|
|
878
|
+
};
|
|
879
|
+
return field.required ? described : { anyOf: [described, { type: 'null' }], title: field.label };
|
|
880
|
+
}
|
|
881
|
+
function pascal(key) {
|
|
882
|
+
return key
|
|
883
|
+
.split(/[^a-zA-Z0-9]+/)
|
|
884
|
+
.filter(Boolean)
|
|
885
|
+
.map((w) => w[0].toUpperCase() + w.slice(1))
|
|
886
|
+
.join('');
|
|
887
|
+
}
|
|
888
|
+
/** OpenAPI document with typed record schemas and paths for each entity. */
|
|
889
|
+
function buildTenantOpenApiDocument(entities, opts = {}) {
|
|
890
|
+
const doc = buildOpenApiDocument(opts);
|
|
891
|
+
doc.info.title = `Platform API${opts.tenantName ? ` — ${opts.tenantName}` : ''}`;
|
|
892
|
+
const recordOps = exports.API_OPERATIONS.filter((op) => op.path.startsWith('/entities/{entityKey}'));
|
|
893
|
+
for (const entity of entities) {
|
|
894
|
+
const name = pascal(entity.key);
|
|
895
|
+
const properties = {};
|
|
896
|
+
for (const field of entity.fields)
|
|
897
|
+
properties[field.key] = fieldValueJsonSchema(field);
|
|
898
|
+
doc.components.schemas[`${name}Data`] = {
|
|
899
|
+
type: 'object',
|
|
900
|
+
properties,
|
|
901
|
+
additionalProperties: false,
|
|
902
|
+
};
|
|
903
|
+
doc.components.schemas[`${name}Input`] = {
|
|
904
|
+
type: 'object',
|
|
905
|
+
properties,
|
|
906
|
+
required: entity.fields
|
|
907
|
+
.filter((f) => f.required && f.defaultValue === null)
|
|
908
|
+
.map((f) => f.key),
|
|
909
|
+
additionalProperties: false,
|
|
910
|
+
};
|
|
911
|
+
const record = {
|
|
912
|
+
type: 'object',
|
|
913
|
+
properties: {
|
|
914
|
+
...jsonSchema(records_1.recordSchema, 'output').properties,
|
|
915
|
+
data: { $ref: `#/components/schemas/${name}Data` },
|
|
916
|
+
},
|
|
917
|
+
};
|
|
918
|
+
doc.components.schemas[`${name}Record`] = record;
|
|
919
|
+
const ref = { $ref: `#/components/schemas/${name}Record` };
|
|
920
|
+
for (const op of recordOps) {
|
|
921
|
+
const path = op.path.replace('{entityKey}', entity.key);
|
|
922
|
+
const response = op.response === undefined
|
|
923
|
+
? undefined
|
|
924
|
+
: op.method === 'get' && !op.path.endsWith('{id}')
|
|
925
|
+
? {
|
|
926
|
+
type: 'object',
|
|
927
|
+
properties: {
|
|
928
|
+
data: { type: 'array', items: ref },
|
|
929
|
+
meta: jsonSchema(pagination_1.pageMetaSchema, 'output'),
|
|
930
|
+
},
|
|
931
|
+
}
|
|
932
|
+
: { type: 'object', properties: { data: ref } };
|
|
933
|
+
const body = op.method === 'post' && op.body
|
|
934
|
+
? {
|
|
935
|
+
type: 'object',
|
|
936
|
+
properties: { data: { $ref: `#/components/schemas/${name}Input` } },
|
|
937
|
+
required: ['data'],
|
|
938
|
+
}
|
|
939
|
+
: op.method === 'patch'
|
|
940
|
+
? {
|
|
941
|
+
type: 'object',
|
|
942
|
+
properties: {
|
|
943
|
+
data: { type: 'object', properties, additionalProperties: false },
|
|
944
|
+
version: { type: 'integer' },
|
|
945
|
+
},
|
|
946
|
+
required: ['data'],
|
|
947
|
+
}
|
|
948
|
+
: undefined;
|
|
949
|
+
doc.paths[path] ??= {};
|
|
950
|
+
doc.paths[path][op.method] = {
|
|
951
|
+
...operationObject({ ...op, path, tag: entity.pluralName }, { response, body }),
|
|
952
|
+
operationId: `${op.method}${name}${op.path.endsWith('{id}') ? 'ById' : ''}${op.path.endsWith('restore') ? 'Restore' : ''}${op.path.endsWith('permanent') ? 'Permanent' : ''}`,
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return doc;
|
|
957
|
+
}
|
|
958
|
+
//# sourceMappingURL=openapi.js.map
|