@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.
Files changed (151) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +595 -0
  3. package/dist/bin/generateSpec.d.ts +25 -0
  4. package/dist/bin/generateSpec.js +61 -0
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.js +2 -0
  7. package/dist/endpoints/interactiveAuth.d.ts +4 -0
  8. package/dist/endpoints/interactiveAuth.js +27 -0
  9. package/dist/endpoints/spec.d.ts +5 -0
  10. package/dist/endpoints/spec.js +39 -0
  11. package/dist/index.d.ts +9 -0
  12. package/dist/index.js +67 -0
  13. package/dist/options.d.ts +2 -0
  14. package/dist/options.js +44 -0
  15. package/dist/spec/build.d.ts +14 -0
  16. package/dist/spec/build.js +36 -0
  17. package/dist/spec/buildDocument.d.ts +15 -0
  18. package/dist/spec/buildDocument.js +234 -0
  19. package/dist/spec/components.d.ts +46 -0
  20. package/dist/spec/components.js +280 -0
  21. package/dist/spec/downconvert.d.ts +3 -0
  22. package/dist/spec/downconvert.js +55 -0
  23. package/dist/spec/entitySchemas.d.ts +15 -0
  24. package/dist/spec/entitySchemas.js +246 -0
  25. package/dist/spec/fields.d.ts +5 -0
  26. package/dist/spec/fields.js +44 -0
  27. package/dist/spec/filters.d.ts +11 -0
  28. package/dist/spec/filters.js +74 -0
  29. package/dist/spec/names.d.ts +14 -0
  30. package/dist/spec/names.js +37 -0
  31. package/dist/spec/params.d.ts +47 -0
  32. package/dist/spec/params.js +344 -0
  33. package/dist/spec/paths/auth.d.ts +9 -0
  34. package/dist/spec/paths/auth.js +285 -0
  35. package/dist/spec/paths/collections.d.ts +7 -0
  36. package/dist/spec/paths/collections.js +261 -0
  37. package/dist/spec/paths/custom.d.ts +9 -0
  38. package/dist/spec/paths/custom.js +41 -0
  39. package/dist/spec/paths/globals.d.ts +7 -0
  40. package/dist/spec/paths/globals.js +68 -0
  41. package/dist/spec/paths/jobs.d.ts +7 -0
  42. package/dist/spec/paths/jobs.js +130 -0
  43. package/dist/spec/paths/versions.d.ts +18 -0
  44. package/dist/spec/paths/versions.js +243 -0
  45. package/dist/spec/tags.d.ts +27 -0
  46. package/dist/spec/tags.js +79 -0
  47. package/dist/translations/index.d.ts +6 -0
  48. package/dist/translations/index.js +96 -0
  49. package/dist/translations/locales/ar.d.ts +2 -0
  50. package/dist/translations/locales/ar.js +76 -0
  51. package/dist/translations/locales/az.d.ts +2 -0
  52. package/dist/translations/locales/az.js +76 -0
  53. package/dist/translations/locales/bg.d.ts +2 -0
  54. package/dist/translations/locales/bg.js +76 -0
  55. package/dist/translations/locales/bnBd.d.ts +2 -0
  56. package/dist/translations/locales/bnBd.js +76 -0
  57. package/dist/translations/locales/bnIn.d.ts +2 -0
  58. package/dist/translations/locales/bnIn.js +76 -0
  59. package/dist/translations/locales/ca.d.ts +2 -0
  60. package/dist/translations/locales/ca.js +76 -0
  61. package/dist/translations/locales/cs.d.ts +2 -0
  62. package/dist/translations/locales/cs.js +76 -0
  63. package/dist/translations/locales/da.d.ts +2 -0
  64. package/dist/translations/locales/da.js +76 -0
  65. package/dist/translations/locales/de.d.ts +2 -0
  66. package/dist/translations/locales/de.js +76 -0
  67. package/dist/translations/locales/en.d.ts +2 -0
  68. package/dist/translations/locales/en.js +76 -0
  69. package/dist/translations/locales/es.d.ts +2 -0
  70. package/dist/translations/locales/es.js +76 -0
  71. package/dist/translations/locales/et.d.ts +2 -0
  72. package/dist/translations/locales/et.js +76 -0
  73. package/dist/translations/locales/fa.d.ts +2 -0
  74. package/dist/translations/locales/fa.js +76 -0
  75. package/dist/translations/locales/fr.d.ts +2 -0
  76. package/dist/translations/locales/fr.js +76 -0
  77. package/dist/translations/locales/he.d.ts +2 -0
  78. package/dist/translations/locales/he.js +76 -0
  79. package/dist/translations/locales/hr.d.ts +2 -0
  80. package/dist/translations/locales/hr.js +76 -0
  81. package/dist/translations/locales/hu.d.ts +2 -0
  82. package/dist/translations/locales/hu.js +76 -0
  83. package/dist/translations/locales/hy.d.ts +2 -0
  84. package/dist/translations/locales/hy.js +76 -0
  85. package/dist/translations/locales/id.d.ts +2 -0
  86. package/dist/translations/locales/id.js +76 -0
  87. package/dist/translations/locales/is.d.ts +2 -0
  88. package/dist/translations/locales/is.js +76 -0
  89. package/dist/translations/locales/it.d.ts +2 -0
  90. package/dist/translations/locales/it.js +76 -0
  91. package/dist/translations/locales/ja.d.ts +2 -0
  92. package/dist/translations/locales/ja.js +76 -0
  93. package/dist/translations/locales/ko.d.ts +2 -0
  94. package/dist/translations/locales/ko.js +76 -0
  95. package/dist/translations/locales/lt.d.ts +2 -0
  96. package/dist/translations/locales/lt.js +76 -0
  97. package/dist/translations/locales/lv.d.ts +2 -0
  98. package/dist/translations/locales/lv.js +76 -0
  99. package/dist/translations/locales/my.d.ts +2 -0
  100. package/dist/translations/locales/my.js +76 -0
  101. package/dist/translations/locales/nb.d.ts +2 -0
  102. package/dist/translations/locales/nb.js +76 -0
  103. package/dist/translations/locales/nl.d.ts +2 -0
  104. package/dist/translations/locales/nl.js +76 -0
  105. package/dist/translations/locales/pl.d.ts +2 -0
  106. package/dist/translations/locales/pl.js +76 -0
  107. package/dist/translations/locales/pt.d.ts +2 -0
  108. package/dist/translations/locales/pt.js +76 -0
  109. package/dist/translations/locales/ro.d.ts +2 -0
  110. package/dist/translations/locales/ro.js +76 -0
  111. package/dist/translations/locales/rs.d.ts +2 -0
  112. package/dist/translations/locales/rs.js +76 -0
  113. package/dist/translations/locales/rsLatin.d.ts +2 -0
  114. package/dist/translations/locales/rsLatin.js +76 -0
  115. package/dist/translations/locales/ru.d.ts +2 -0
  116. package/dist/translations/locales/ru.js +76 -0
  117. package/dist/translations/locales/sk.d.ts +2 -0
  118. package/dist/translations/locales/sk.js +76 -0
  119. package/dist/translations/locales/sl.d.ts +2 -0
  120. package/dist/translations/locales/sl.js +76 -0
  121. package/dist/translations/locales/sv.d.ts +2 -0
  122. package/dist/translations/locales/sv.js +76 -0
  123. package/dist/translations/locales/ta.d.ts +2 -0
  124. package/dist/translations/locales/ta.js +76 -0
  125. package/dist/translations/locales/th.d.ts +2 -0
  126. package/dist/translations/locales/th.js +76 -0
  127. package/dist/translations/locales/tr.d.ts +2 -0
  128. package/dist/translations/locales/tr.js +76 -0
  129. package/dist/translations/locales/uk.d.ts +2 -0
  130. package/dist/translations/locales/uk.js +76 -0
  131. package/dist/translations/locales/vi.d.ts +2 -0
  132. package/dist/translations/locales/vi.js +76 -0
  133. package/dist/translations/locales/zh.d.ts +2 -0
  134. package/dist/translations/locales/zh.js +76 -0
  135. package/dist/translations/locales/zhTw.d.ts +2 -0
  136. package/dist/translations/locales/zhTw.js +76 -0
  137. package/dist/translations/types.d.ts +82 -0
  138. package/dist/translations/types.js +1 -0
  139. package/dist/types.d.ts +183 -0
  140. package/dist/types.js +1 -0
  141. package/dist/ui/createUiPlugin.d.ts +14 -0
  142. package/dist/ui/createUiPlugin.js +28 -0
  143. package/dist/ui/html.d.ts +8 -0
  144. package/dist/ui/html.js +8 -0
  145. package/dist/ui/scalar.d.ts +1 -0
  146. package/dist/ui/scalar.js +12 -0
  147. package/dist/ui/swagger.d.ts +1 -0
  148. package/dist/ui/swagger.js +12 -0
  149. package/dist/utils.d.ts +3 -0
  150. package/dist/utils.js +13 -0
  151. package/package.json +84 -0
@@ -0,0 +1,74 @@
1
+ const SYSTEM_COLLECTIONS = new Set([
2
+ 'payload-jobs',
3
+ 'payload-locked-documents',
4
+ 'payload-preferences',
5
+ 'payload-migrations',
6
+ 'payload-folders'
7
+ ]);
8
+ const HTTP_METHODS = [
9
+ 'get',
10
+ 'post',
11
+ 'patch',
12
+ 'put',
13
+ 'delete'
14
+ ];
15
+ const matchesEntity = (matcher, { slug, kind })=>{
16
+ if ('string' == typeof matcher) return matcher === slug;
17
+ if (matcher instanceof RegExp) return matcher.test(slug);
18
+ return matcher.kind === kind && matcher.slug === slug;
19
+ };
20
+ const anyMatch = (matchers, entity)=>matchers.some((m)=>matchesEntity(m, entity));
21
+ const isHiddenCollection = (collection)=>{
22
+ if (true === collection.hidden) return true;
23
+ const adminHidden = collection.admin?.hidden;
24
+ return true === adminHidden || 'function' == typeof adminHidden;
25
+ };
26
+ const passesIncludeExclude = (entity, filters)=>{
27
+ if (filters.include.length > 0 && !anyMatch(filters.include, entity)) return false;
28
+ if (anyMatch(filters.exclude, entity)) return false;
29
+ return true;
30
+ };
31
+ const shouldIncludeCollection = (collection, filters)=>{
32
+ const { slug } = collection;
33
+ if (SYSTEM_COLLECTIONS.has(slug) && !filters.includeSystem) return false;
34
+ if (!filters.includeHidden && isHiddenCollection(collection)) return false;
35
+ return passesIncludeExclude({
36
+ slug,
37
+ kind: 'collection'
38
+ }, filters);
39
+ };
40
+ const shouldIncludeGlobal = (global, filters)=>passesIncludeExclude({
41
+ slug: global.slug,
42
+ kind: 'global'
43
+ }, filters);
44
+ const ruleMatchesMethod = (rule, method)=>{
45
+ if (void 0 === rule.method) return true;
46
+ return Array.isArray(rule.method) ? rule.method.includes(method) : rule.method === method;
47
+ };
48
+ const ruleMatchesSlug = (rule, slug)=>{
49
+ if (void 0 === rule.slug) return true;
50
+ return rule.slug instanceof RegExp ? rule.slug.test(slug) : rule.slug === slug;
51
+ };
52
+ const ruleMatches = (rule, { method, slug, kind, path })=>ruleMatchesMethod(rule, method) && ruleMatchesSlug(rule, slug) && (void 0 === rule.kind || rule.kind === kind) && (void 0 === rule.path || rule.path.test(path));
53
+ const isOperationExcluded = (filters, op)=>{
54
+ if (filters.excludeOperations.some((rule)=>ruleMatches(rule, op))) return true;
55
+ return filters.excludeWhen?.(op) ?? false;
56
+ };
57
+ const filterOperations = ({ paths, slug, kind, filters })=>{
58
+ if (0 === filters.excludeOperations.length && !filters.excludeWhen) return paths;
59
+ for (const [path, item] of Object.entries(paths)){
60
+ if (!item) continue;
61
+ let remaining = 0;
62
+ const ops = item;
63
+ for (const method of HTTP_METHODS)if (ops[method]) if (isOperationExcluded(filters, {
64
+ method,
65
+ slug,
66
+ kind,
67
+ path
68
+ })) delete ops[method];
69
+ else remaining += 1;
70
+ if (0 === remaining) delete paths[path];
71
+ }
72
+ return paths;
73
+ };
74
+ export { filterOperations, shouldIncludeCollection, shouldIncludeGlobal };
@@ -0,0 +1,14 @@
1
+ export declare const schemaName: (slug: string) => string;
2
+ export declare const blockSchemaName: (slug: string) => string;
3
+ export declare const globalSchemaName: (slug: string) => string;
4
+ export declare const listSchemaName: (base: string) => string;
5
+ export declare const createSchemaName: (base: string) => string;
6
+ export declare const updateSchemaName: (base: string) => string;
7
+ export declare const querySchemaName: (base: string) => string;
8
+ export declare const selectSchemaName: (base: string) => string;
9
+ export declare const populateSchemaName: (base: string) => string;
10
+ export declare const joinsSchemaName: (base: string) => string;
11
+ export declare const refTo: (name: string) => string;
12
+ type JsonValue = Record<string, unknown> | unknown[] | string | number | boolean | null;
13
+ export declare const rewriteRefs: (node: JsonValue, blockSlugs?: Set<string>) => JsonValue;
14
+ export {};
@@ -0,0 +1,37 @@
1
+ import { upperFirst } from "../utils.js";
2
+ const schemaName = (slug)=>upperFirst(slug.replace(/-([a-z])/g, (_, c)=>c.toUpperCase()));
3
+ const blockSchemaName = (slug)=>{
4
+ const stripped = slug.replace(/^block[-_]?/i, '').replace(/[-_]?block$/i, '');
5
+ return `Block${schemaName(stripped || slug)}`;
6
+ };
7
+ const globalSchemaName = (slug)=>`Global${schemaName(slug)}`;
8
+ const listSchemaName = (base)=>`${base}List`;
9
+ const createSchemaName = (base)=>`${base}Create`;
10
+ const updateSchemaName = (base)=>`${base}Update`;
11
+ const querySchemaName = (base)=>`${base}QueryOperations`;
12
+ const selectSchemaName = (base)=>`${base}Select`;
13
+ const populateSchemaName = (base)=>`${base}Populate`;
14
+ const joinsSchemaName = (base)=>`${base}Joins`;
15
+ const refTo = (name)=>`#/components/schemas/${name}`;
16
+ const REF = /^#\/(?:definitions|\$defs|components\/schemas)\/(.+)$/;
17
+ const normalizeRef = (ref, blockSlugs)=>{
18
+ const match = REF.exec(ref);
19
+ if (!match) return ref;
20
+ const captured = match[1];
21
+ const pascal = schemaName(captured);
22
+ const blockSlug = [
23
+ ...blockSlugs
24
+ ].find((s)=>s === captured || schemaName(s) === pascal);
25
+ if (blockSlug) return `#/components/schemas/${blockSchemaName(blockSlug)}`;
26
+ return `#/components/schemas/${pascal}`;
27
+ };
28
+ const rewriteRefs = (node, blockSlugs = new Set())=>{
29
+ if (Array.isArray(node)) return node.map((item)=>rewriteRefs(item, blockSlugs));
30
+ if (node && 'object' == typeof node) {
31
+ const out = {};
32
+ for (const [key, value] of Object.entries(node))out[key] = '$ref' === key && 'string' == typeof value ? normalizeRef(value, blockSlugs) : rewriteRefs(value, blockSlugs);
33
+ return out;
34
+ }
35
+ return node;
36
+ };
37
+ export { blockSchemaName, createSchemaName, globalSchemaName, joinsSchemaName, listSchemaName, populateSchemaName, querySchemaName, refTo, rewriteRefs, schemaName, selectSchemaName, updateSchemaName };
@@ -0,0 +1,47 @@
1
+ import type { Field } from 'payload';
2
+ import type { ParameterObject, SchemaObject } from '@scalar/openapi-types/3.2';
3
+ import type { BuildContext } from '../types.js';
4
+ export declare const buildSelectSchema: ({ fields, ctx }: {
5
+ fields: Field[];
6
+ ctx: BuildContext;
7
+ }) => SchemaObject;
8
+ export declare const buildPopulateSchema: ({ fields, ctx, }: {
9
+ fields: Field[];
10
+ ctx: BuildContext;
11
+ }) => SchemaObject | undefined;
12
+ export declare const buildJoinsSchema: ({ fields, ctx }: {
13
+ fields: Field[];
14
+ ctx: BuildContext;
15
+ }) => SchemaObject | undefined;
16
+ export interface ParamSchemas {
17
+ select: SchemaObject;
18
+ populate?: SchemaObject;
19
+ joins?: SchemaObject;
20
+ }
21
+ export declare const buildParamSchemas: ({ fields, ctx }: {
22
+ fields: Field[];
23
+ ctx: BuildContext;
24
+ }) => ParamSchemas;
25
+ export declare const collectionHasFilters: (fields: Field[]) => boolean;
26
+ export declare const buildQueryOperationsSchema: ({ base, fields, ctx, }: {
27
+ base: string;
28
+ fields: Field[];
29
+ ctx: BuildContext;
30
+ }) => SchemaObject;
31
+ export interface ReadParamRefs {
32
+ select: boolean;
33
+ populate: boolean;
34
+ joins: boolean;
35
+ }
36
+ export declare const commonReadParams: ({ base, ctx, refs, }: {
37
+ base: string;
38
+ ctx: BuildContext;
39
+ refs: ReadParamRefs;
40
+ }) => ParameterObject[];
41
+ export declare const whereParam: (base: string) => ParameterObject;
42
+ export declare const buildListParams: ({ base, fields, ctx, refs, }: {
43
+ base: string;
44
+ fields: Field[];
45
+ ctx: BuildContext;
46
+ refs: ReadParamRefs;
47
+ }) => ParameterObject[];
@@ -0,0 +1,344 @@
1
+ import { makeT } from "../translations/index.js";
2
+ import { exposableFields } from "./fields.js";
3
+ import { joinsSchemaName, populateSchemaName, querySchemaName, refTo, selectSchemaName } from "./names.js";
4
+ const fieldName = (field)=>'name' in field && 'string' == typeof field.name ? field.name : void 0;
5
+ const relationTargets = (field)=>{
6
+ if ('relationship' !== field.type && 'upload' !== field.type) return [];
7
+ const relTo = field.relationTo;
8
+ return Array.isArray(relTo) ? relTo : [
9
+ relTo
10
+ ];
11
+ };
12
+ const buildSelectSchema = ({ fields, ctx })=>{
13
+ const properties = {};
14
+ for (const field of exposableFields(fields)){
15
+ const name = fieldName(field);
16
+ if (name) properties[name] = {
17
+ type: 'boolean'
18
+ };
19
+ }
20
+ return {
21
+ type: 'object',
22
+ additionalProperties: false,
23
+ description: makeT(ctx.i18n)('schemaSelect'),
24
+ properties
25
+ };
26
+ };
27
+ const buildPopulateSchema = ({ fields, ctx })=>{
28
+ const targets = new Set();
29
+ for (const field of exposableFields(fields))for (const target of relationTargets(field))targets.add(target);
30
+ if (0 === targets.size) return;
31
+ const properties = {};
32
+ for (const target of targets)properties[target] = {
33
+ type: 'object',
34
+ additionalProperties: {
35
+ type: 'boolean'
36
+ }
37
+ };
38
+ return {
39
+ type: 'object',
40
+ additionalProperties: false,
41
+ description: makeT(ctx.i18n)('schemaPopulate'),
42
+ properties
43
+ };
44
+ };
45
+ const buildJoinsSchema = ({ fields, ctx })=>{
46
+ const joinControls = {
47
+ type: 'object',
48
+ additionalProperties: false,
49
+ properties: {
50
+ limit: {
51
+ type: 'integer'
52
+ },
53
+ page: {
54
+ type: 'integer'
55
+ },
56
+ sort: {
57
+ type: 'string'
58
+ },
59
+ count: {
60
+ type: 'boolean'
61
+ },
62
+ where: {
63
+ type: 'object',
64
+ additionalProperties: true
65
+ }
66
+ }
67
+ };
68
+ const properties = {};
69
+ for (const field of exposableFields(fields)){
70
+ if ('join' !== field.type) continue;
71
+ const name = fieldName(field);
72
+ if (name) properties[name] = joinControls;
73
+ }
74
+ if (0 === Object.keys(properties).length) return;
75
+ return {
76
+ type: 'object',
77
+ additionalProperties: false,
78
+ description: makeT(ctx.i18n)('schemaJoins'),
79
+ properties
80
+ };
81
+ };
82
+ const buildParamSchemas = ({ fields, ctx })=>({
83
+ select: buildSelectSchema({
84
+ fields,
85
+ ctx
86
+ }),
87
+ populate: buildPopulateSchema({
88
+ fields,
89
+ ctx
90
+ }),
91
+ joins: buildJoinsSchema({
92
+ fields,
93
+ ctx
94
+ })
95
+ });
96
+ const OPERATORS_BY_TYPE = {
97
+ text: [
98
+ 'equals',
99
+ 'not_equals',
100
+ 'like',
101
+ 'contains',
102
+ 'in',
103
+ 'not_in',
104
+ 'exists'
105
+ ],
106
+ textarea: [
107
+ 'equals',
108
+ 'not_equals',
109
+ 'like',
110
+ 'contains',
111
+ 'in',
112
+ 'not_in',
113
+ 'exists'
114
+ ],
115
+ email: [
116
+ 'equals',
117
+ 'not_equals',
118
+ 'like',
119
+ 'contains',
120
+ 'in',
121
+ 'not_in',
122
+ 'exists'
123
+ ],
124
+ code: [
125
+ 'equals',
126
+ 'not_equals',
127
+ 'like',
128
+ 'contains',
129
+ 'exists'
130
+ ],
131
+ number: [
132
+ 'equals',
133
+ 'not_equals',
134
+ 'greater_than',
135
+ 'greater_than_equal',
136
+ 'less_than',
137
+ 'less_than_equal',
138
+ 'in',
139
+ 'not_in',
140
+ 'exists'
141
+ ],
142
+ date: [
143
+ 'equals',
144
+ 'not_equals',
145
+ 'greater_than',
146
+ 'greater_than_equal',
147
+ 'less_than',
148
+ 'less_than_equal',
149
+ 'exists'
150
+ ],
151
+ checkbox: [
152
+ 'equals',
153
+ 'not_equals',
154
+ 'exists'
155
+ ],
156
+ radio: [
157
+ 'equals',
158
+ 'not_equals',
159
+ 'in',
160
+ 'not_in',
161
+ 'exists'
162
+ ],
163
+ select: [
164
+ 'equals',
165
+ 'not_equals',
166
+ 'in',
167
+ 'not_in',
168
+ 'exists'
169
+ ],
170
+ relationship: [
171
+ 'equals',
172
+ 'not_equals',
173
+ 'in',
174
+ 'not_in',
175
+ 'exists'
176
+ ],
177
+ upload: [
178
+ 'equals',
179
+ 'not_equals',
180
+ 'in',
181
+ 'not_in',
182
+ 'exists'
183
+ ]
184
+ };
185
+ const fieldHasQueryOperators = (field)=>Boolean(OPERATORS_BY_TYPE[field.type]);
186
+ const collectionHasFilters = (fields)=>exposableFields(fields).some((f)=>fieldName(f) && fieldHasQueryOperators(f));
187
+ const buildQueryOperationsSchema = ({ base, fields, ctx })=>{
188
+ const properties = {};
189
+ for (const field of exposableFields(fields)){
190
+ const name = fieldName(field);
191
+ const operators = OPERATORS_BY_TYPE[field.type];
192
+ if (name && operators) properties[name] = {
193
+ type: 'object',
194
+ additionalProperties: false,
195
+ properties: Object.fromEntries(operators.map((op)=>[
196
+ op,
197
+ {}
198
+ ]))
199
+ };
200
+ }
201
+ const selfRef = {
202
+ $ref: refTo(querySchemaName(base))
203
+ };
204
+ properties.and = {
205
+ type: 'array',
206
+ items: selfRef
207
+ };
208
+ properties.or = {
209
+ type: 'array',
210
+ items: selfRef
211
+ };
212
+ return {
213
+ type: 'object',
214
+ additionalProperties: false,
215
+ description: makeT(ctx.i18n)('schemaWhere'),
216
+ properties
217
+ };
218
+ };
219
+ const objectParam = (name, ref)=>({
220
+ name,
221
+ in: 'query',
222
+ content: {
223
+ 'application/json': {
224
+ schema: ref ? {
225
+ $ref: ref
226
+ } : {
227
+ type: 'object',
228
+ additionalProperties: true
229
+ }
230
+ }
231
+ }
232
+ });
233
+ const localeParam = (ctx)=>({
234
+ name: 'locale',
235
+ in: 'query',
236
+ description: makeT(ctx.i18n)('paramLocale'),
237
+ schema: ctx.locales.length > 0 ? {
238
+ type: 'string',
239
+ enum: [
240
+ ...ctx.locales,
241
+ 'all'
242
+ ]
243
+ } : {
244
+ type: 'string'
245
+ }
246
+ });
247
+ const fallbackLocaleParam = (ctx)=>({
248
+ name: 'fallback-locale',
249
+ in: 'query',
250
+ description: makeT(ctx.i18n)('paramFallbackLocale'),
251
+ schema: ctx.locales.length > 0 ? {
252
+ type: 'string',
253
+ enum: [
254
+ ...ctx.locales,
255
+ 'none'
256
+ ]
257
+ } : {
258
+ type: 'string'
259
+ }
260
+ });
261
+ const commonReadParams = ({ base, ctx, refs })=>{
262
+ const params = [
263
+ {
264
+ name: 'depth',
265
+ in: 'query',
266
+ description: makeT(ctx.i18n)('paramDepth'),
267
+ schema: {
268
+ type: 'integer'
269
+ }
270
+ },
271
+ localeParam(ctx),
272
+ fallbackLocaleParam(ctx),
273
+ objectParam('select', refs.select ? refTo(selectSchemaName(base)) : void 0),
274
+ {
275
+ name: 'flattenLocales',
276
+ in: 'query',
277
+ description: makeT(ctx.i18n)('paramFlattenLocales'),
278
+ schema: {
279
+ type: 'boolean'
280
+ }
281
+ },
282
+ {
283
+ name: 'draft',
284
+ in: 'query',
285
+ description: makeT(ctx.i18n)('paramDraft'),
286
+ schema: {
287
+ type: 'boolean'
288
+ }
289
+ },
290
+ {
291
+ name: 'trash',
292
+ in: 'query',
293
+ description: makeT(ctx.i18n)('paramTrash'),
294
+ schema: {
295
+ type: 'boolean'
296
+ }
297
+ }
298
+ ];
299
+ if (refs.populate) params.push(objectParam('populate', refTo(populateSchemaName(base))));
300
+ if (refs.joins) params.push(objectParam('joins', refTo(joinsSchemaName(base))));
301
+ return params;
302
+ };
303
+ const whereParam = (base)=>objectParam('where', refTo(querySchemaName(base)));
304
+ const buildListParams = ({ base, fields, ctx, refs })=>{
305
+ const params = [
306
+ {
307
+ name: 'page',
308
+ in: 'query',
309
+ schema: {
310
+ type: 'integer'
311
+ }
312
+ },
313
+ {
314
+ name: 'limit',
315
+ in: 'query',
316
+ schema: {
317
+ type: 'integer'
318
+ }
319
+ },
320
+ {
321
+ name: 'pagination',
322
+ in: 'query',
323
+ schema: {
324
+ type: 'boolean'
325
+ }
326
+ },
327
+ {
328
+ name: 'sort',
329
+ in: 'query',
330
+ description: makeT(ctx.i18n)('paramSort'),
331
+ schema: {
332
+ type: 'string'
333
+ }
334
+ },
335
+ ...commonReadParams({
336
+ base,
337
+ ctx,
338
+ refs
339
+ })
340
+ ];
341
+ if (collectionHasFilters(fields)) params.push(whereParam(base));
342
+ return params;
343
+ };
344
+ export { buildJoinsSchema, buildListParams, buildParamSchemas, buildPopulateSchema, buildQueryOperationsSchema, buildSelectSchema, collectionHasFilters, commonReadParams, whereParam };
@@ -0,0 +1,9 @@
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 buildAuthPaths: ({ collection, ctx, includeAdmin, nestedTags, }: {
5
+ collection: SanitizedCollectionConfig;
6
+ ctx: BuildContext;
7
+ includeAdmin: boolean;
8
+ nestedTags: boolean;
9
+ }) => PathsObject;