@seshuk/payload-plugin-openapi 0.1.0
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/README.md +595 -0
- package/dist/bin/generateSpec.d.ts +25 -0
- package/dist/bin/generateSpec.js +61 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -0
- package/dist/endpoints/interactiveAuth.d.ts +4 -0
- package/dist/endpoints/interactiveAuth.js +27 -0
- package/dist/endpoints/spec.d.ts +5 -0
- package/dist/endpoints/spec.js +39 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +67 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +44 -0
- package/dist/spec/build.d.ts +14 -0
- package/dist/spec/build.js +36 -0
- package/dist/spec/buildDocument.d.ts +15 -0
- package/dist/spec/buildDocument.js +234 -0
- package/dist/spec/components.d.ts +46 -0
- package/dist/spec/components.js +280 -0
- package/dist/spec/downconvert.d.ts +3 -0
- package/dist/spec/downconvert.js +55 -0
- package/dist/spec/entitySchemas.d.ts +15 -0
- package/dist/spec/entitySchemas.js +246 -0
- package/dist/spec/fields.d.ts +5 -0
- package/dist/spec/fields.js +44 -0
- package/dist/spec/filters.d.ts +11 -0
- package/dist/spec/filters.js +74 -0
- package/dist/spec/names.d.ts +14 -0
- package/dist/spec/names.js +37 -0
- package/dist/spec/params.d.ts +47 -0
- package/dist/spec/params.js +344 -0
- package/dist/spec/paths/auth.d.ts +9 -0
- package/dist/spec/paths/auth.js +285 -0
- package/dist/spec/paths/collections.d.ts +7 -0
- package/dist/spec/paths/collections.js +261 -0
- package/dist/spec/paths/custom.d.ts +9 -0
- package/dist/spec/paths/custom.js +41 -0
- package/dist/spec/paths/globals.d.ts +7 -0
- package/dist/spec/paths/globals.js +68 -0
- package/dist/spec/paths/jobs.d.ts +7 -0
- package/dist/spec/paths/jobs.js +130 -0
- package/dist/spec/paths/versions.d.ts +18 -0
- package/dist/spec/paths/versions.js +243 -0
- package/dist/spec/tags.d.ts +27 -0
- package/dist/spec/tags.js +79 -0
- package/dist/translations/index.d.ts +6 -0
- package/dist/translations/index.js +96 -0
- package/dist/translations/locales/ar.d.ts +2 -0
- package/dist/translations/locales/ar.js +76 -0
- package/dist/translations/locales/az.d.ts +2 -0
- package/dist/translations/locales/az.js +76 -0
- package/dist/translations/locales/bg.d.ts +2 -0
- package/dist/translations/locales/bg.js +76 -0
- package/dist/translations/locales/bnBd.d.ts +2 -0
- package/dist/translations/locales/bnBd.js +76 -0
- package/dist/translations/locales/bnIn.d.ts +2 -0
- package/dist/translations/locales/bnIn.js +76 -0
- package/dist/translations/locales/ca.d.ts +2 -0
- package/dist/translations/locales/ca.js +76 -0
- package/dist/translations/locales/cs.d.ts +2 -0
- package/dist/translations/locales/cs.js +76 -0
- package/dist/translations/locales/da.d.ts +2 -0
- package/dist/translations/locales/da.js +76 -0
- package/dist/translations/locales/de.d.ts +2 -0
- package/dist/translations/locales/de.js +76 -0
- package/dist/translations/locales/en.d.ts +2 -0
- package/dist/translations/locales/en.js +76 -0
- package/dist/translations/locales/es.d.ts +2 -0
- package/dist/translations/locales/es.js +76 -0
- package/dist/translations/locales/et.d.ts +2 -0
- package/dist/translations/locales/et.js +76 -0
- package/dist/translations/locales/fa.d.ts +2 -0
- package/dist/translations/locales/fa.js +76 -0
- package/dist/translations/locales/fr.d.ts +2 -0
- package/dist/translations/locales/fr.js +76 -0
- package/dist/translations/locales/he.d.ts +2 -0
- package/dist/translations/locales/he.js +76 -0
- package/dist/translations/locales/hr.d.ts +2 -0
- package/dist/translations/locales/hr.js +76 -0
- package/dist/translations/locales/hu.d.ts +2 -0
- package/dist/translations/locales/hu.js +76 -0
- package/dist/translations/locales/hy.d.ts +2 -0
- package/dist/translations/locales/hy.js +76 -0
- package/dist/translations/locales/id.d.ts +2 -0
- package/dist/translations/locales/id.js +76 -0
- package/dist/translations/locales/is.d.ts +2 -0
- package/dist/translations/locales/is.js +76 -0
- package/dist/translations/locales/it.d.ts +2 -0
- package/dist/translations/locales/it.js +76 -0
- package/dist/translations/locales/ja.d.ts +2 -0
- package/dist/translations/locales/ja.js +76 -0
- package/dist/translations/locales/ko.d.ts +2 -0
- package/dist/translations/locales/ko.js +76 -0
- package/dist/translations/locales/lt.d.ts +2 -0
- package/dist/translations/locales/lt.js +76 -0
- package/dist/translations/locales/lv.d.ts +2 -0
- package/dist/translations/locales/lv.js +76 -0
- package/dist/translations/locales/my.d.ts +2 -0
- package/dist/translations/locales/my.js +76 -0
- package/dist/translations/locales/nb.d.ts +2 -0
- package/dist/translations/locales/nb.js +76 -0
- package/dist/translations/locales/nl.d.ts +2 -0
- package/dist/translations/locales/nl.js +76 -0
- package/dist/translations/locales/pl.d.ts +2 -0
- package/dist/translations/locales/pl.js +76 -0
- package/dist/translations/locales/pt.d.ts +2 -0
- package/dist/translations/locales/pt.js +76 -0
- package/dist/translations/locales/ro.d.ts +2 -0
- package/dist/translations/locales/ro.js +76 -0
- package/dist/translations/locales/rs.d.ts +2 -0
- package/dist/translations/locales/rs.js +76 -0
- package/dist/translations/locales/rsLatin.d.ts +2 -0
- package/dist/translations/locales/rsLatin.js +76 -0
- package/dist/translations/locales/ru.d.ts +2 -0
- package/dist/translations/locales/ru.js +76 -0
- package/dist/translations/locales/sk.d.ts +2 -0
- package/dist/translations/locales/sk.js +76 -0
- package/dist/translations/locales/sl.d.ts +2 -0
- package/dist/translations/locales/sl.js +76 -0
- package/dist/translations/locales/sv.d.ts +2 -0
- package/dist/translations/locales/sv.js +76 -0
- package/dist/translations/locales/ta.d.ts +2 -0
- package/dist/translations/locales/ta.js +76 -0
- package/dist/translations/locales/th.d.ts +2 -0
- package/dist/translations/locales/th.js +76 -0
- package/dist/translations/locales/tr.d.ts +2 -0
- package/dist/translations/locales/tr.js +76 -0
- package/dist/translations/locales/uk.d.ts +2 -0
- package/dist/translations/locales/uk.js +76 -0
- package/dist/translations/locales/vi.d.ts +2 -0
- package/dist/translations/locales/vi.js +76 -0
- package/dist/translations/locales/zh.d.ts +2 -0
- package/dist/translations/locales/zh.js +76 -0
- package/dist/translations/locales/zhTw.d.ts +2 -0
- package/dist/translations/locales/zhTw.js +76 -0
- package/dist/translations/types.d.ts +82 -0
- package/dist/translations/types.js +1 -0
- package/dist/types.d.ts +183 -0
- package/dist/types.js +1 -0
- package/dist/ui/createUiPlugin.d.ts +14 -0
- package/dist/ui/createUiPlugin.js +28 -0
- package/dist/ui/html.d.ts +8 -0
- package/dist/ui/html.js +8 -0
- package/dist/ui/scalar.d.ts +1 -0
- package/dist/ui/scalar.js +12 -0
- package/dist/ui/swagger.d.ts +1 -0
- package/dist/ui/swagger.js +12 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +13 -0
- package/package.json +84 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { makeT } from "../../translations/index.js";
|
|
2
|
+
import { ERRORS, errorResponses, jsonBody, jsonResponse, messageResponse } from "../components.js";
|
|
3
|
+
import { refTo, schemaName } from "../names.js";
|
|
4
|
+
import { authTagName } from "../tags.js";
|
|
5
|
+
const identifierProps = (auth)=>{
|
|
6
|
+
const loginWithUsername = Boolean(auth?.loginWithUsername);
|
|
7
|
+
const usernameOnly = 'object' == typeof auth?.loginWithUsername && false === auth.loginWithUsername.requireEmail;
|
|
8
|
+
if (loginWithUsername && usernameOnly) return {
|
|
9
|
+
properties: {
|
|
10
|
+
username: {
|
|
11
|
+
type: 'string'
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
required: [
|
|
15
|
+
'username'
|
|
16
|
+
]
|
|
17
|
+
};
|
|
18
|
+
if (loginWithUsername) return {
|
|
19
|
+
properties: {
|
|
20
|
+
email: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
format: 'email'
|
|
23
|
+
},
|
|
24
|
+
username: {
|
|
25
|
+
type: 'string'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: []
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
properties: {
|
|
32
|
+
email: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
format: 'email'
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
required: [
|
|
38
|
+
'email'
|
|
39
|
+
]
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const buildAuthPaths = ({ collection, ctx, includeAdmin, nestedTags })=>{
|
|
43
|
+
const auth = collection.auth;
|
|
44
|
+
if (!auth || auth.disableLocalStrategy) return {};
|
|
45
|
+
const t = makeT(ctx.i18n);
|
|
46
|
+
const name = schemaName(collection.slug);
|
|
47
|
+
const base = `${ctx.apiRoute}/${collection.slug}`;
|
|
48
|
+
const tag = [
|
|
49
|
+
nestedTags ? authTagName(name) : name
|
|
50
|
+
];
|
|
51
|
+
const ident = identifierProps(auth);
|
|
52
|
+
const userRef = {
|
|
53
|
+
$ref: refTo(name)
|
|
54
|
+
};
|
|
55
|
+
const op = (operationId, codes, extra)=>({
|
|
56
|
+
tags: tag,
|
|
57
|
+
operationId,
|
|
58
|
+
...extra,
|
|
59
|
+
responses: {
|
|
60
|
+
...extra.responses,
|
|
61
|
+
...errorResponses(codes, t)
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const paths = {
|
|
65
|
+
[`${base}/login`]: {
|
|
66
|
+
post: op(`login${name}`, ERRORS.login, {
|
|
67
|
+
requestBody: jsonBody({
|
|
68
|
+
type: 'object',
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
properties: {
|
|
71
|
+
...ident.properties,
|
|
72
|
+
password: {
|
|
73
|
+
type: 'string'
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
required: [
|
|
77
|
+
...ident.required,
|
|
78
|
+
'password'
|
|
79
|
+
]
|
|
80
|
+
}),
|
|
81
|
+
responses: {
|
|
82
|
+
200: jsonResponse(t('authLogin'), {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
message: {
|
|
86
|
+
type: 'string'
|
|
87
|
+
},
|
|
88
|
+
user: userRef,
|
|
89
|
+
token: {
|
|
90
|
+
type: 'string'
|
|
91
|
+
},
|
|
92
|
+
exp: {
|
|
93
|
+
type: 'integer'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
},
|
|
100
|
+
[`${base}/logout`]: {
|
|
101
|
+
post: op(`logout${name}`, ERRORS.session, {
|
|
102
|
+
responses: messageResponse(t('authLogout'))
|
|
103
|
+
})
|
|
104
|
+
},
|
|
105
|
+
[`${base}/me`]: {
|
|
106
|
+
get: op(`me${name}`, ERRORS.session, {
|
|
107
|
+
responses: {
|
|
108
|
+
200: jsonResponse(t('authMe'), {
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: {
|
|
111
|
+
user: userRef,
|
|
112
|
+
collection: {
|
|
113
|
+
type: 'string'
|
|
114
|
+
},
|
|
115
|
+
token: {
|
|
116
|
+
type: 'string'
|
|
117
|
+
},
|
|
118
|
+
exp: {
|
|
119
|
+
type: 'integer'
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
},
|
|
126
|
+
[`${base}/refresh-token`]: {
|
|
127
|
+
post: op(`refreshToken${name}`, ERRORS.session, {
|
|
128
|
+
responses: {
|
|
129
|
+
200: jsonResponse(t('authRefreshToken'), {
|
|
130
|
+
type: 'object',
|
|
131
|
+
properties: {
|
|
132
|
+
message: {
|
|
133
|
+
type: 'string'
|
|
134
|
+
},
|
|
135
|
+
refreshedToken: {
|
|
136
|
+
type: 'string'
|
|
137
|
+
},
|
|
138
|
+
exp: {
|
|
139
|
+
type: 'integer'
|
|
140
|
+
},
|
|
141
|
+
user: userRef
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
},
|
|
147
|
+
[`${base}/forgot-password`]: {
|
|
148
|
+
post: op(`forgotPassword${name}`, ERRORS.authAction, {
|
|
149
|
+
requestBody: jsonBody({
|
|
150
|
+
type: 'object',
|
|
151
|
+
additionalProperties: false,
|
|
152
|
+
properties: {
|
|
153
|
+
email: {
|
|
154
|
+
type: 'string',
|
|
155
|
+
format: 'email'
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
required: [
|
|
159
|
+
'email'
|
|
160
|
+
]
|
|
161
|
+
}),
|
|
162
|
+
responses: messageResponse(t('authForgotPassword'))
|
|
163
|
+
})
|
|
164
|
+
},
|
|
165
|
+
[`${base}/reset-password`]: {
|
|
166
|
+
post: op(`resetPassword${name}`, ERRORS.authAction, {
|
|
167
|
+
requestBody: jsonBody({
|
|
168
|
+
type: 'object',
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
properties: {
|
|
171
|
+
token: {
|
|
172
|
+
type: 'string'
|
|
173
|
+
},
|
|
174
|
+
password: {
|
|
175
|
+
type: 'string'
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
required: [
|
|
179
|
+
'token',
|
|
180
|
+
'password'
|
|
181
|
+
]
|
|
182
|
+
}),
|
|
183
|
+
responses: {
|
|
184
|
+
200: jsonResponse(t('authResetPassword'), {
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
message: {
|
|
188
|
+
type: 'string'
|
|
189
|
+
},
|
|
190
|
+
token: {
|
|
191
|
+
type: 'string'
|
|
192
|
+
},
|
|
193
|
+
user: userRef
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
if (includeAdmin) {
|
|
201
|
+
paths[`${base}/first-register`] = {
|
|
202
|
+
post: op(`firstRegister${name}`, ERRORS.create, {
|
|
203
|
+
requestBody: jsonBody({
|
|
204
|
+
$ref: refTo(`${name}Create`)
|
|
205
|
+
}),
|
|
206
|
+
responses: {
|
|
207
|
+
200: jsonResponse(t('authFirstRegister'), {
|
|
208
|
+
type: 'object',
|
|
209
|
+
properties: {
|
|
210
|
+
message: {
|
|
211
|
+
type: 'string'
|
|
212
|
+
},
|
|
213
|
+
user: userRef,
|
|
214
|
+
token: {
|
|
215
|
+
type: 'string'
|
|
216
|
+
},
|
|
217
|
+
exp: {
|
|
218
|
+
type: 'integer'
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
};
|
|
225
|
+
paths[`${base}/init`] = {
|
|
226
|
+
get: op(`init${name}`, ERRORS.session, {
|
|
227
|
+
responses: {
|
|
228
|
+
200: jsonResponse(t('authInit'), {
|
|
229
|
+
type: 'object',
|
|
230
|
+
properties: {
|
|
231
|
+
initialized: {
|
|
232
|
+
type: 'boolean'
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
};
|
|
239
|
+
paths[`${base}/access`] = {
|
|
240
|
+
get: op(`access${name}`, ERRORS.session, {
|
|
241
|
+
responses: {
|
|
242
|
+
200: jsonResponse(t('authAccess'), {
|
|
243
|
+
type: 'object',
|
|
244
|
+
additionalProperties: true
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
})
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (auth.maxLoginAttempts && auth.maxLoginAttempts > 0) paths[`${base}/unlock`] = {
|
|
251
|
+
post: op(`unlock${name}`, ERRORS.authAction, {
|
|
252
|
+
requestBody: jsonBody({
|
|
253
|
+
type: 'object',
|
|
254
|
+
additionalProperties: false,
|
|
255
|
+
properties: {
|
|
256
|
+
email: {
|
|
257
|
+
type: 'string',
|
|
258
|
+
format: 'email'
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
required: [
|
|
262
|
+
'email'
|
|
263
|
+
]
|
|
264
|
+
}),
|
|
265
|
+
responses: messageResponse(t('authUnlock'))
|
|
266
|
+
})
|
|
267
|
+
};
|
|
268
|
+
if (auth.verify) paths[`${base}/verify/{id}`] = {
|
|
269
|
+
post: op(`verify${name}`, ERRORS.authAction, {
|
|
270
|
+
parameters: [
|
|
271
|
+
{
|
|
272
|
+
name: 'id',
|
|
273
|
+
in: 'path',
|
|
274
|
+
required: true,
|
|
275
|
+
schema: {
|
|
276
|
+
type: 'string'
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
],
|
|
280
|
+
responses: messageResponse(t('authVerify'))
|
|
281
|
+
})
|
|
282
|
+
};
|
|
283
|
+
return paths;
|
|
284
|
+
};
|
|
285
|
+
export { buildAuthPaths };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SanitizedCollectionConfig } from 'payload';
|
|
2
|
+
import type { PathsObject } from '@scalar/openapi-types/3.2';
|
|
3
|
+
import type { BuildContext } from '../../types.js';
|
|
4
|
+
export declare const buildCollectionPaths: ({ collection, ctx, }: {
|
|
5
|
+
collection: SanitizedCollectionConfig;
|
|
6
|
+
ctx: BuildContext;
|
|
7
|
+
}) => PathsObject;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { makeT } from "../../translations/index.js";
|
|
2
|
+
import { ERRORS, SECURITY_SCHEME_NAME, errorResponses, isOpenToPublic, jsonOk, uploadRequestBody } from "../components.js";
|
|
3
|
+
import { createSchemaName, listSchemaName, refTo, schemaName, updateSchemaName } from "../names.js";
|
|
4
|
+
import { buildListParams, buildParamSchemas, commonReadParams } from "../params.js";
|
|
5
|
+
const buildCollectionPaths = ({ collection, ctx })=>{
|
|
6
|
+
const t = makeT(ctx.i18n);
|
|
7
|
+
const name = schemaName(collection.slug);
|
|
8
|
+
const base = `${ctx.apiRoute}/${collection.slug}`;
|
|
9
|
+
const docRef = {
|
|
10
|
+
$ref: refTo(name)
|
|
11
|
+
};
|
|
12
|
+
const listRef = {
|
|
13
|
+
$ref: refTo(listSchemaName(name))
|
|
14
|
+
};
|
|
15
|
+
const createRef = {
|
|
16
|
+
$ref: refTo(createSchemaName(name))
|
|
17
|
+
};
|
|
18
|
+
const updateRef = {
|
|
19
|
+
$ref: refTo(updateSchemaName(name))
|
|
20
|
+
};
|
|
21
|
+
const idType = 'number' === ctx.defaultIDType ? 'integer' : 'string';
|
|
22
|
+
const secured = isOpenToPublic(collection.access?.read) ? void 0 : [
|
|
23
|
+
{
|
|
24
|
+
[SECURITY_SCHEME_NAME]: []
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
const allowBulk = true !== collection.disableBulkEdit;
|
|
28
|
+
const allowDuplicate = true !== collection.disableDuplicate;
|
|
29
|
+
const paramSchemas = buildParamSchemas({
|
|
30
|
+
fields: collection.fields,
|
|
31
|
+
ctx
|
|
32
|
+
});
|
|
33
|
+
const refs = {
|
|
34
|
+
select: true,
|
|
35
|
+
populate: Boolean(paramSchemas.populate),
|
|
36
|
+
joins: Boolean(paramSchemas.joins)
|
|
37
|
+
};
|
|
38
|
+
const isUpload = Boolean(collection.upload);
|
|
39
|
+
const fileRequiredOnCreate = 'object' == typeof collection.upload ? false !== collection.upload.filesRequiredOnCreate : true;
|
|
40
|
+
const requestBody = (ref, fileRequired)=>isUpload ? uploadRequestBody({
|
|
41
|
+
bodyRef: ref,
|
|
42
|
+
fileRequired,
|
|
43
|
+
t
|
|
44
|
+
}) : {
|
|
45
|
+
content: {
|
|
46
|
+
'application/json': {
|
|
47
|
+
schema: ref
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const mutationSchema = {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
message: {
|
|
55
|
+
type: 'string'
|
|
56
|
+
},
|
|
57
|
+
doc: docRef
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const listResponse = {
|
|
61
|
+
...jsonOk(t('collectionList'), listRef),
|
|
62
|
+
...errorResponses(ERRORS.list, t)
|
|
63
|
+
};
|
|
64
|
+
const findByIdResponse = {
|
|
65
|
+
...jsonOk(t('collectionDoc'), docRef),
|
|
66
|
+
...errorResponses(ERRORS.read, t)
|
|
67
|
+
};
|
|
68
|
+
const createResponse = {
|
|
69
|
+
...jsonOk(t('collectionCreated'), mutationSchema),
|
|
70
|
+
...errorResponses(ERRORS.create, t)
|
|
71
|
+
};
|
|
72
|
+
const updateResponse = {
|
|
73
|
+
...jsonOk(t('collectionUpdated'), mutationSchema),
|
|
74
|
+
...errorResponses(ERRORS.update, t)
|
|
75
|
+
};
|
|
76
|
+
const deleteResponse = {
|
|
77
|
+
...jsonOk(t('collectionDeleted'), mutationSchema),
|
|
78
|
+
...errorResponses(ERRORS["delete"], t)
|
|
79
|
+
};
|
|
80
|
+
const bulkSchema = {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
message: {
|
|
84
|
+
type: 'string'
|
|
85
|
+
},
|
|
86
|
+
docs: {
|
|
87
|
+
type: 'array',
|
|
88
|
+
items: docRef
|
|
89
|
+
},
|
|
90
|
+
errors: {
|
|
91
|
+
type: 'array',
|
|
92
|
+
items: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
message: {
|
|
96
|
+
type: 'string'
|
|
97
|
+
},
|
|
98
|
+
id: {
|
|
99
|
+
type: idType
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const bulkUpdateResponse = {
|
|
107
|
+
...jsonOk(t('collectionBulkUpdate'), bulkSchema),
|
|
108
|
+
...errorResponses(ERRORS.update, t)
|
|
109
|
+
};
|
|
110
|
+
const bulkDeleteResponse = {
|
|
111
|
+
...jsonOk(t('collectionBulkDelete'), bulkSchema),
|
|
112
|
+
...errorResponses(ERRORS["delete"], t)
|
|
113
|
+
};
|
|
114
|
+
const countResponse = {
|
|
115
|
+
...jsonOk(t('collectionCount'), {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
totalDocs: {
|
|
119
|
+
type: 'integer'
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
...errorResponses(ERRORS.list, t)
|
|
124
|
+
};
|
|
125
|
+
const whereParameter = buildListParams({
|
|
126
|
+
base: name,
|
|
127
|
+
fields: collection.fields,
|
|
128
|
+
ctx,
|
|
129
|
+
refs
|
|
130
|
+
}).find((p)=>'where' === p.name);
|
|
131
|
+
const bulkParams = whereParameter ? [
|
|
132
|
+
whereParameter
|
|
133
|
+
] : [];
|
|
134
|
+
const bulkOps = allowBulk ? {
|
|
135
|
+
patch: {
|
|
136
|
+
tags: [
|
|
137
|
+
name
|
|
138
|
+
],
|
|
139
|
+
operationId: `update${name}`,
|
|
140
|
+
parameters: bulkParams,
|
|
141
|
+
requestBody: requestBody(updateRef, false),
|
|
142
|
+
responses: bulkUpdateResponse,
|
|
143
|
+
security: secured
|
|
144
|
+
},
|
|
145
|
+
delete: {
|
|
146
|
+
tags: [
|
|
147
|
+
name
|
|
148
|
+
],
|
|
149
|
+
operationId: `delete${name}`,
|
|
150
|
+
parameters: bulkParams,
|
|
151
|
+
responses: bulkDeleteResponse,
|
|
152
|
+
security: secured
|
|
153
|
+
}
|
|
154
|
+
} : {};
|
|
155
|
+
const paths = {
|
|
156
|
+
[base]: {
|
|
157
|
+
get: {
|
|
158
|
+
tags: [
|
|
159
|
+
name
|
|
160
|
+
],
|
|
161
|
+
operationId: `find${name}`,
|
|
162
|
+
parameters: buildListParams({
|
|
163
|
+
base: name,
|
|
164
|
+
fields: collection.fields,
|
|
165
|
+
ctx,
|
|
166
|
+
refs
|
|
167
|
+
}),
|
|
168
|
+
responses: listResponse,
|
|
169
|
+
security: secured
|
|
170
|
+
},
|
|
171
|
+
post: {
|
|
172
|
+
tags: [
|
|
173
|
+
name
|
|
174
|
+
],
|
|
175
|
+
operationId: `create${name}`,
|
|
176
|
+
requestBody: requestBody(createRef, fileRequiredOnCreate),
|
|
177
|
+
responses: createResponse,
|
|
178
|
+
security: secured
|
|
179
|
+
},
|
|
180
|
+
...bulkOps
|
|
181
|
+
},
|
|
182
|
+
[`${base}/count`]: {
|
|
183
|
+
get: {
|
|
184
|
+
tags: [
|
|
185
|
+
name
|
|
186
|
+
],
|
|
187
|
+
operationId: `count${name}`,
|
|
188
|
+
parameters: bulkParams,
|
|
189
|
+
responses: countResponse,
|
|
190
|
+
security: secured
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
[`${base}/{id}`]: {
|
|
194
|
+
parameters: [
|
|
195
|
+
{
|
|
196
|
+
name: 'id',
|
|
197
|
+
in: 'path',
|
|
198
|
+
required: true,
|
|
199
|
+
schema: {
|
|
200
|
+
type: idType
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
get: {
|
|
205
|
+
tags: [
|
|
206
|
+
name
|
|
207
|
+
],
|
|
208
|
+
operationId: `find${name}ById`,
|
|
209
|
+
parameters: commonReadParams({
|
|
210
|
+
base: name,
|
|
211
|
+
ctx,
|
|
212
|
+
refs
|
|
213
|
+
}),
|
|
214
|
+
responses: findByIdResponse,
|
|
215
|
+
security: secured
|
|
216
|
+
},
|
|
217
|
+
patch: {
|
|
218
|
+
tags: [
|
|
219
|
+
name
|
|
220
|
+
],
|
|
221
|
+
operationId: `update${name}ById`,
|
|
222
|
+
requestBody: requestBody(updateRef, false),
|
|
223
|
+
responses: updateResponse,
|
|
224
|
+
security: secured
|
|
225
|
+
},
|
|
226
|
+
delete: {
|
|
227
|
+
tags: [
|
|
228
|
+
name
|
|
229
|
+
],
|
|
230
|
+
operationId: `delete${name}ById`,
|
|
231
|
+
responses: deleteResponse,
|
|
232
|
+
security: secured
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
if (allowDuplicate) paths[`${base}/{id}/duplicate`] = {
|
|
237
|
+
parameters: [
|
|
238
|
+
{
|
|
239
|
+
name: 'id',
|
|
240
|
+
in: 'path',
|
|
241
|
+
required: true,
|
|
242
|
+
schema: {
|
|
243
|
+
type: idType
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
],
|
|
247
|
+
post: {
|
|
248
|
+
tags: [
|
|
249
|
+
name
|
|
250
|
+
],
|
|
251
|
+
operationId: `duplicate${name}`,
|
|
252
|
+
responses: {
|
|
253
|
+
...jsonOk(t('collectionDuplicated'), mutationSchema),
|
|
254
|
+
...errorResponses(ERRORS.create, t)
|
|
255
|
+
},
|
|
256
|
+
security: secured
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
return paths;
|
|
260
|
+
};
|
|
261
|
+
export { buildCollectionPaths };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SanitizedCollectionConfig, SanitizedConfig, SanitizedGlobalConfig } from 'payload';
|
|
2
|
+
import type { PathsObject } from '@scalar/openapi-types/3.2';
|
|
3
|
+
import type { BuildContext } from '../../types.js';
|
|
4
|
+
export declare const buildCustomEndpointPaths: ({ config, collections, globals, ctx, }: {
|
|
5
|
+
config: SanitizedConfig;
|
|
6
|
+
collections: SanitizedCollectionConfig[];
|
|
7
|
+
globals: SanitizedGlobalConfig[];
|
|
8
|
+
ctx: BuildContext;
|
|
9
|
+
}) => PathsObject;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const getOpenapiMeta = (endpoint)=>{
|
|
2
|
+
const meta = endpoint.custom?.openapi;
|
|
3
|
+
return meta && 'object' == typeof meta ? meta : void 0;
|
|
4
|
+
};
|
|
5
|
+
const normalizePath = (prefix, path)=>{
|
|
6
|
+
const joined = `${prefix}${path.startsWith('/') ? path : `/${path}`}`;
|
|
7
|
+
return joined.replace(/:([A-Za-z0-9_]+)/g, '{$1}');
|
|
8
|
+
};
|
|
9
|
+
const collect = ({ endpoints, prefix, out })=>{
|
|
10
|
+
if (!endpoints) return;
|
|
11
|
+
for (const endpoint of endpoints){
|
|
12
|
+
const meta = getOpenapiMeta(endpoint);
|
|
13
|
+
if (!meta) continue;
|
|
14
|
+
const path = normalizePath(prefix, endpoint.path);
|
|
15
|
+
const method = endpoint.method.toLowerCase();
|
|
16
|
+
out[path] = {
|
|
17
|
+
...out[path],
|
|
18
|
+
[method]: meta
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const buildCustomEndpointPaths = ({ config, collections, globals, ctx })=>{
|
|
23
|
+
const out = {};
|
|
24
|
+
collect({
|
|
25
|
+
endpoints: config.endpoints,
|
|
26
|
+
prefix: '',
|
|
27
|
+
out
|
|
28
|
+
});
|
|
29
|
+
for (const collection of collections)collect({
|
|
30
|
+
endpoints: collection.endpoints,
|
|
31
|
+
prefix: `${ctx.apiRoute}/${collection.slug}`,
|
|
32
|
+
out
|
|
33
|
+
});
|
|
34
|
+
for (const global of globals)collect({
|
|
35
|
+
endpoints: global.endpoints,
|
|
36
|
+
prefix: `${ctx.apiRoute}/globals/${global.slug}`,
|
|
37
|
+
out
|
|
38
|
+
});
|
|
39
|
+
return out;
|
|
40
|
+
};
|
|
41
|
+
export { buildCustomEndpointPaths };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SanitizedGlobalConfig } from 'payload';
|
|
2
|
+
import type { PathsObject } from '@scalar/openapi-types/3.2';
|
|
3
|
+
import type { BuildContext } from '../../types.js';
|
|
4
|
+
export declare const buildGlobalPaths: ({ global, ctx, }: {
|
|
5
|
+
global: SanitizedGlobalConfig;
|
|
6
|
+
ctx: BuildContext;
|
|
7
|
+
}) => PathsObject;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { makeT } from "../../translations/index.js";
|
|
2
|
+
import { ERRORS, SECURITY_SCHEME_NAME, errorResponses, isOpenToPublic, jsonOk } from "../components.js";
|
|
3
|
+
import { globalSchemaName, refTo, updateSchemaName } from "../names.js";
|
|
4
|
+
import { buildParamSchemas, commonReadParams } from "../params.js";
|
|
5
|
+
const buildGlobalPaths = ({ global, ctx })=>{
|
|
6
|
+
const t = makeT(ctx.i18n);
|
|
7
|
+
const name = globalSchemaName(global.slug);
|
|
8
|
+
const docRef = {
|
|
9
|
+
$ref: refTo(name)
|
|
10
|
+
};
|
|
11
|
+
const updateRef = {
|
|
12
|
+
$ref: refTo(updateSchemaName(name))
|
|
13
|
+
};
|
|
14
|
+
const secured = isOpenToPublic(global.access?.read) ? void 0 : [
|
|
15
|
+
{
|
|
16
|
+
[SECURITY_SCHEME_NAME]: []
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
const paramSchemas = buildParamSchemas({
|
|
20
|
+
fields: global.fields,
|
|
21
|
+
ctx
|
|
22
|
+
});
|
|
23
|
+
const refs = {
|
|
24
|
+
select: true,
|
|
25
|
+
populate: Boolean(paramSchemas.populate),
|
|
26
|
+
joins: Boolean(paramSchemas.joins)
|
|
27
|
+
};
|
|
28
|
+
const okDoc = jsonOk(t('globalDoc'), docRef);
|
|
29
|
+
return {
|
|
30
|
+
[`${ctx.apiRoute}/globals/${global.slug}`]: {
|
|
31
|
+
get: {
|
|
32
|
+
tags: [
|
|
33
|
+
name
|
|
34
|
+
],
|
|
35
|
+
operationId: `find${name}`,
|
|
36
|
+
parameters: commonReadParams({
|
|
37
|
+
base: name,
|
|
38
|
+
ctx,
|
|
39
|
+
refs
|
|
40
|
+
}),
|
|
41
|
+
responses: {
|
|
42
|
+
...okDoc,
|
|
43
|
+
...errorResponses(ERRORS.globalRead, t)
|
|
44
|
+
},
|
|
45
|
+
security: secured
|
|
46
|
+
},
|
|
47
|
+
post: {
|
|
48
|
+
tags: [
|
|
49
|
+
name
|
|
50
|
+
],
|
|
51
|
+
operationId: `update${name}`,
|
|
52
|
+
requestBody: {
|
|
53
|
+
content: {
|
|
54
|
+
'application/json': {
|
|
55
|
+
schema: updateRef
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
responses: {
|
|
60
|
+
...okDoc,
|
|
61
|
+
...errorResponses(ERRORS.globalUpdate, t)
|
|
62
|
+
},
|
|
63
|
+
security: secured
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export { buildGlobalPaths };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SanitizedConfig } from 'payload';
|
|
2
|
+
import type { PathsObject } from '@scalar/openapi-types/3.2';
|
|
3
|
+
import type { BuildContext } from '../../types.js';
|
|
4
|
+
export declare const buildJobsPaths: ({ config, ctx }: {
|
|
5
|
+
config: SanitizedConfig;
|
|
6
|
+
ctx: BuildContext;
|
|
7
|
+
}) => PathsObject;
|