@nocobase/plugin-api-doc 0.13.0-alpha.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 +661 -0
- package/README.md +80 -0
- package/README.zh-CN.md +79 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/Document.d.ts +4 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +48583 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -0
- package/dist/locale/en-US.d.ts +2 -0
- package/dist/locale/en-US.js +5 -0
- package/dist/locale/index.d.ts +4 -0
- package/dist/locale/index.js +20 -0
- package/dist/locale/zh-CN.d.ts +6 -0
- package/dist/locale/zh-CN.js +9 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +11 -0
- package/dist/server/server.d.ts +8 -0
- package/dist/server/server.js +51 -0
- package/dist/server/swagger/base-swagger.d.ts +49 -0
- package/dist/server/swagger/base-swagger.js +54 -0
- package/dist/server/swagger/collections/components/field-type-map.d.ts +22 -0
- package/dist/server/swagger/collections/components/field-type-map.js +34 -0
- package/dist/server/swagger/collections/components/index.d.ts +24 -0
- package/dist/server/swagger/collections/components/index.js +18 -0
- package/dist/server/swagger/collections/components/parameters.d.ts +5 -0
- package/dist/server/swagger/collections/components/parameters.js +173 -0
- package/dist/server/swagger/collections/components/schemas.d.ts +23 -0
- package/dist/server/swagger/collections/components/schemas.js +91 -0
- package/dist/server/swagger/collections/index.d.ts +31 -0
- package/dist/server/swagger/collections/index.js +22 -0
- package/dist/server/swagger/collections/paths/associations/index.d.ts +6 -0
- package/dist/server/swagger/collections/paths/associations/index.js +32 -0
- package/dist/server/swagger/collections/paths/associations/multiple-association.d.ts +6 -0
- package/dist/server/swagger/collections/paths/associations/multiple-association.js +106 -0
- package/dist/server/swagger/collections/paths/associations/single-association.d.ts +5 -0
- package/dist/server/swagger/collections/paths/associations/single-association.js +88 -0
- package/dist/server/swagger/collections/paths/collection.d.ts +201 -0
- package/dist/server/swagger/collections/paths/collection.js +333 -0
- package/dist/server/swagger/collections/paths/index.d.ts +4 -0
- package/dist/server/swagger/collections/paths/index.js +30 -0
- package/dist/server/swagger/collections/tags/index.d.ts +6 -0
- package/dist/server/swagger/collections/tags/index.js +26 -0
- package/dist/server/swagger/constants.d.ts +10 -0
- package/dist/server/swagger/constants.js +14 -0
- package/dist/server/swagger/helpers.d.ts +171 -0
- package/dist/server/swagger/helpers.js +111 -0
- package/dist/server/swagger/index.d.ts +48 -0
- package/dist/server/swagger/index.js +221 -0
- package/dist/server/swagger/loader.d.ts +4 -0
- package/dist/server/swagger/loader.js +54 -0
- package/dist/server/swagger/merge.d.ts +1 -0
- package/dist/server/swagger/merge.js +13 -0
- package/dist/swagger.d.ts +43 -0
- package/dist/swagger.js +46 -0
- package/package.json +24 -0
- package/server.d.ts +3 -0
- package/server.js +1 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index = require('./index');
|
|
6
|
+
|
|
7
|
+
function relationTypeToString(field) {
|
|
8
|
+
return {
|
|
9
|
+
belongsTo: "Many to one",
|
|
10
|
+
hasOne: "One to one",
|
|
11
|
+
hasMany: "One to many",
|
|
12
|
+
belongsToMany: "Many to many"
|
|
13
|
+
}[field.type];
|
|
14
|
+
}
|
|
15
|
+
function ListActionTemplate({ collection, relationField }) {
|
|
16
|
+
return {
|
|
17
|
+
get: {
|
|
18
|
+
tags: [relationField ? `${collection.name}.${relationField.name}` : collection.name],
|
|
19
|
+
summary: relationField ? `Return a list of ${relationTypeToString(relationField)} relationship` : `Returns a list of the collection`,
|
|
20
|
+
parameters: [
|
|
21
|
+
{
|
|
22
|
+
name: "page",
|
|
23
|
+
in: "query",
|
|
24
|
+
description: "page number",
|
|
25
|
+
required: false,
|
|
26
|
+
schema: {
|
|
27
|
+
type: "integer"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "pageSize",
|
|
32
|
+
in: "query",
|
|
33
|
+
description: "page size",
|
|
34
|
+
required: false,
|
|
35
|
+
schema: {
|
|
36
|
+
type: "integer"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
$ref: "#/components/parameters/filter"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
$ref: "#/components/parameters/sort"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
$ref: "#/components/parameters/fields"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
$ref: "#/components/parameters/appends"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
$ref: "#/components/parameters/except"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
responses: {
|
|
56
|
+
"200": {
|
|
57
|
+
description: "OK",
|
|
58
|
+
content: {
|
|
59
|
+
"application/json": {
|
|
60
|
+
schema: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
data: {
|
|
64
|
+
type: "array",
|
|
65
|
+
items: {
|
|
66
|
+
$ref: `#/components/schemas/${collection.name}`
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
meta: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
count: {
|
|
73
|
+
type: "integer",
|
|
74
|
+
description: "total count"
|
|
75
|
+
},
|
|
76
|
+
page: {
|
|
77
|
+
type: "integer",
|
|
78
|
+
description: "current page"
|
|
79
|
+
},
|
|
80
|
+
pageSize: {
|
|
81
|
+
type: "integer",
|
|
82
|
+
description: "items count per page"
|
|
83
|
+
},
|
|
84
|
+
totalPage: {
|
|
85
|
+
type: "integer",
|
|
86
|
+
description: "total page"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function GetActionTemplate(options) {
|
|
100
|
+
const { collection, relationField } = options;
|
|
101
|
+
return {
|
|
102
|
+
get: {
|
|
103
|
+
tags: [relationField ? `${collection.name}.${relationField.name}` : collection.name],
|
|
104
|
+
summary: `Return a record${relationField ? ` of ${relationTypeToString(relationField)}` : ""}`,
|
|
105
|
+
parameters: [
|
|
106
|
+
{
|
|
107
|
+
$ref: "#/components/parameters/filterByTk"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
$ref: "#/components/parameters/filter"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
$ref: "#/components/parameters/sort"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
$ref: "#/components/parameters/fields"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
$ref: "#/components/parameters/appends"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
$ref: "#/components/parameters/except"
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
responses: {
|
|
126
|
+
"200": {
|
|
127
|
+
description: "OK",
|
|
128
|
+
content: {
|
|
129
|
+
"application/json": {
|
|
130
|
+
schema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
properties: {
|
|
133
|
+
data: {
|
|
134
|
+
$ref: `#/components/schemas/${collection.name}`
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function CreateActionTemplate(options) {
|
|
146
|
+
const { collection, relationField } = options;
|
|
147
|
+
return {
|
|
148
|
+
post: {
|
|
149
|
+
tags: [relationField ? `${collection.name}.${relationField.name}` : collection.name],
|
|
150
|
+
summary: relationField ? `Create and associate a record` : `Create record`,
|
|
151
|
+
parameters: [
|
|
152
|
+
{
|
|
153
|
+
$ref: "#/components/parameters/whitelist"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
$ref: "#/components/parameters/blacklist"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
requestBody: {
|
|
160
|
+
content: {
|
|
161
|
+
"application/json": {
|
|
162
|
+
schema: {
|
|
163
|
+
$ref: `#/components/schemas/${collection.name}.form`
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
responses: {
|
|
169
|
+
"200": {
|
|
170
|
+
description: "OK",
|
|
171
|
+
content: {
|
|
172
|
+
"application/json": {
|
|
173
|
+
schema: {
|
|
174
|
+
type: "object",
|
|
175
|
+
properties: {
|
|
176
|
+
data: {
|
|
177
|
+
$ref: `#/components/schemas/${collection.name}`
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function UpdateActionTemplate(options) {
|
|
189
|
+
const { collection, relationField } = options;
|
|
190
|
+
return {
|
|
191
|
+
post: {
|
|
192
|
+
tags: [relationField ? `${collection.name}.${relationField.name}` : collection.name],
|
|
193
|
+
summary: relationField ? `Update the relationship record` : `Update record`,
|
|
194
|
+
parameters: [
|
|
195
|
+
{
|
|
196
|
+
$ref: "#/components/parameters/filterByTk"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
$ref: "#/components/parameters/filter"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
$ref: "#/components/parameters/whitelist"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
$ref: "#/components/parameters/blacklist"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
requestBody: {
|
|
209
|
+
content: {
|
|
210
|
+
"application/json": {
|
|
211
|
+
schema: {
|
|
212
|
+
$ref: `#/components/schemas/${collection.name}.form`
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
responses: {
|
|
218
|
+
"200": {
|
|
219
|
+
description: "OK",
|
|
220
|
+
content: {
|
|
221
|
+
"application/json": {
|
|
222
|
+
schema: {
|
|
223
|
+
type: "object",
|
|
224
|
+
properties: {
|
|
225
|
+
data: {
|
|
226
|
+
$ref: `#/components/schemas/${collection.name}`
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function DestroyActionTemplate(options) {
|
|
238
|
+
const { collection, relationField } = options;
|
|
239
|
+
return {
|
|
240
|
+
post: {
|
|
241
|
+
tags: [relationField ? `${collection.name}.${relationField.name}` : collection.name],
|
|
242
|
+
summary: relationField ? `Destroy and disassociate the relationship record` : `Delete record`,
|
|
243
|
+
parameters: [
|
|
244
|
+
{
|
|
245
|
+
$ref: "#/components/parameters/filterByTk"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
$ref: "#/components/parameters/filter"
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
responses: {
|
|
252
|
+
"200": {
|
|
253
|
+
description: "OK"
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function MoveActionTemplate(options) {
|
|
260
|
+
const { collection, relationField } = options;
|
|
261
|
+
return {
|
|
262
|
+
post: {
|
|
263
|
+
tags: [relationField ? `${collection.name}.${relationField.name}` : collection.name],
|
|
264
|
+
summary: relationField ? `Move the relationship record` : `Move record`,
|
|
265
|
+
parameters: [
|
|
266
|
+
{
|
|
267
|
+
name: "sourceId",
|
|
268
|
+
in: "query",
|
|
269
|
+
description: "source id",
|
|
270
|
+
schema: { type: "string" }
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: "targetId",
|
|
274
|
+
in: "query",
|
|
275
|
+
description: "move target id",
|
|
276
|
+
schema: { type: "string" }
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: "method",
|
|
280
|
+
in: "query",
|
|
281
|
+
description: "move method, insertAfter or insertBefore",
|
|
282
|
+
schema: { type: "string" }
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "sortField",
|
|
286
|
+
in: "query",
|
|
287
|
+
description: "sort field name, default is sort",
|
|
288
|
+
schema: { type: "string" }
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: "targetScope",
|
|
292
|
+
in: "query",
|
|
293
|
+
description: "move target scope",
|
|
294
|
+
schema: { type: "string" }
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: "sticky",
|
|
298
|
+
in: "query",
|
|
299
|
+
description: "sticky to top",
|
|
300
|
+
schema: { type: "boolean" }
|
|
301
|
+
}
|
|
302
|
+
],
|
|
303
|
+
responses: {
|
|
304
|
+
"200": {
|
|
305
|
+
description: "OK"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
var collection_default = (collection) => {
|
|
312
|
+
const options = { collection };
|
|
313
|
+
const apiDoc = {
|
|
314
|
+
[`/${collection.name}:list`]: ListActionTemplate(options),
|
|
315
|
+
[`/${collection.name}:get`]: GetActionTemplate(options),
|
|
316
|
+
[`/${collection.name}:create`]: CreateActionTemplate(options),
|
|
317
|
+
[`/${collection.name}:update`]: UpdateActionTemplate(options),
|
|
318
|
+
[`/${collection.name}:destroy`]: DestroyActionTemplate(options)
|
|
319
|
+
};
|
|
320
|
+
if (index.hasSortField(collection)) {
|
|
321
|
+
apiDoc[`/${collection.name}:move`] = MoveActionTemplate(options);
|
|
322
|
+
}
|
|
323
|
+
return apiDoc;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
exports.CreateActionTemplate = CreateActionTemplate;
|
|
327
|
+
exports.DestroyActionTemplate = DestroyActionTemplate;
|
|
328
|
+
exports.GetActionTemplate = GetActionTemplate;
|
|
329
|
+
exports.ListActionTemplate = ListActionTemplate;
|
|
330
|
+
exports.MoveActionTemplate = MoveActionTemplate;
|
|
331
|
+
exports.UpdateActionTemplate = UpdateActionTemplate;
|
|
332
|
+
exports.default = collection_default;
|
|
333
|
+
exports.relationTypeToString = relationTypeToString;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var list = require('./collection');
|
|
6
|
+
var associations = require('./associations');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var list__default = /*#__PURE__*/_interopDefault(list);
|
|
11
|
+
var associations__default = /*#__PURE__*/_interopDefault(associations);
|
|
12
|
+
|
|
13
|
+
var paths_default = (collection, options) => {
|
|
14
|
+
const paths = list__default.default(collection);
|
|
15
|
+
if (options.withAssociation) {
|
|
16
|
+
Object.assign(paths, associations__default.default(collection));
|
|
17
|
+
}
|
|
18
|
+
return paths;
|
|
19
|
+
};
|
|
20
|
+
function hasSortField(collection) {
|
|
21
|
+
for (const field of collection.fields.values()) {
|
|
22
|
+
if (field.type === "sort") {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.default = paths_default;
|
|
30
|
+
exports.hasSortField = hasSortField;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var associations = require('../paths/associations');
|
|
4
|
+
var collection = require('../paths/collection');
|
|
5
|
+
|
|
6
|
+
var tags_default = (collection$1, options) => {
|
|
7
|
+
var _a, _b, _c, _d;
|
|
8
|
+
const associations$1 = associations.associationFields(collection$1);
|
|
9
|
+
const tags = [
|
|
10
|
+
{
|
|
11
|
+
name: collection$1.name,
|
|
12
|
+
description: ((_a = collection$1.options) == null ? void 0 : _a.title) || collection$1.name
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
if (options.withAssociation) {
|
|
16
|
+
for (const field of associations$1) {
|
|
17
|
+
tags.push({
|
|
18
|
+
name: `${collection$1.name}.${field.name}`,
|
|
19
|
+
description: `${collection.relationTypeToString(field)} relationship, ${((_b = collection$1.options) == null ? void 0 : _b.title) || collection$1.name}/${((_d = (_c = field.options) == null ? void 0 : _c.uiSchema) == null ? void 0 : _d.title) || field.name}`
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return tags;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports = tags_default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const SchemaTypeMapping = {
|
|
4
|
+
uid: "string",
|
|
5
|
+
json: "object",
|
|
6
|
+
jsonb: "object",
|
|
7
|
+
text: "string",
|
|
8
|
+
bigInt: "integer",
|
|
9
|
+
sort: "integer",
|
|
10
|
+
context: "string",
|
|
11
|
+
set: "array"
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.SchemaTypeMapping = SchemaTypeMapping;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export declare const createDefaultActionSwagger: ({ collection }: {
|
|
2
|
+
collection: any;
|
|
3
|
+
}) => {
|
|
4
|
+
list: {
|
|
5
|
+
method: string;
|
|
6
|
+
responses: {
|
|
7
|
+
default: {
|
|
8
|
+
content: {
|
|
9
|
+
'application/json': {
|
|
10
|
+
schema: {
|
|
11
|
+
$ref: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
create: {
|
|
19
|
+
method: string;
|
|
20
|
+
requestBody: {
|
|
21
|
+
content: {
|
|
22
|
+
'application/json': {
|
|
23
|
+
schema: {
|
|
24
|
+
$ref: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
get: {
|
|
31
|
+
method: string;
|
|
32
|
+
responses: {
|
|
33
|
+
default: {
|
|
34
|
+
content: {
|
|
35
|
+
'application/json': {
|
|
36
|
+
schema: {
|
|
37
|
+
$ref: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
update: {
|
|
45
|
+
method: string;
|
|
46
|
+
requestBody: {
|
|
47
|
+
content: {
|
|
48
|
+
'application/json': {
|
|
49
|
+
schema: {
|
|
50
|
+
$ref: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
responses: {
|
|
56
|
+
default: {
|
|
57
|
+
content: {
|
|
58
|
+
'application/json': {
|
|
59
|
+
schema: {
|
|
60
|
+
$ref: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
destroy: {
|
|
68
|
+
method: string;
|
|
69
|
+
responses: {
|
|
70
|
+
default: {
|
|
71
|
+
content: {
|
|
72
|
+
'application/json': {
|
|
73
|
+
schema: {
|
|
74
|
+
$ref: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
add: {
|
|
82
|
+
method: string;
|
|
83
|
+
requestBody: {
|
|
84
|
+
content: {
|
|
85
|
+
'application/json': {
|
|
86
|
+
schema: {
|
|
87
|
+
$ref: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
responses: {
|
|
93
|
+
default: {
|
|
94
|
+
content: {
|
|
95
|
+
'application/json': {
|
|
96
|
+
schema: {
|
|
97
|
+
$ref: string;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
set: {
|
|
105
|
+
method: string;
|
|
106
|
+
requestBody: {
|
|
107
|
+
content: {
|
|
108
|
+
'application/json': {
|
|
109
|
+
schema: {
|
|
110
|
+
$ref: string;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
remove: {
|
|
117
|
+
method: string;
|
|
118
|
+
responses: {
|
|
119
|
+
default: {
|
|
120
|
+
content: {
|
|
121
|
+
'application/json': {
|
|
122
|
+
schema: {
|
|
123
|
+
$ref: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
toggle: {
|
|
131
|
+
method: string;
|
|
132
|
+
requestBody: {
|
|
133
|
+
content: {
|
|
134
|
+
'application/json': {
|
|
135
|
+
schema: {
|
|
136
|
+
$ref: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
responses: {
|
|
142
|
+
default: {
|
|
143
|
+
content: {
|
|
144
|
+
'application/json': {
|
|
145
|
+
schema: {
|
|
146
|
+
$ref: string;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
move: {
|
|
154
|
+
method: string;
|
|
155
|
+
requestBody: {
|
|
156
|
+
content: {
|
|
157
|
+
'application/json': {
|
|
158
|
+
schema: {
|
|
159
|
+
$ref: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
export declare const getInterfaceCollection: (options: Record<string, any>) => {
|
|
167
|
+
'/{resourceName}': any[];
|
|
168
|
+
'/{resourceName}/{resourceIndex}': any[];
|
|
169
|
+
'/{associatedName}/{associatedIndex}/{resourceName}': any[];
|
|
170
|
+
'/{associatedName}/{associatedIndex}/{resourceName}/{resourceIndex}': any[];
|
|
171
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const createDefaultActionSwagger = ({ collection }) => {
|
|
4
|
+
const responses = {
|
|
5
|
+
default: {
|
|
6
|
+
content: {
|
|
7
|
+
"application/json": {
|
|
8
|
+
schema: {
|
|
9
|
+
$ref: `#/components/schemas/${collection.name}`
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const requestBody = {
|
|
16
|
+
content: {
|
|
17
|
+
"application/json": {
|
|
18
|
+
schema: {
|
|
19
|
+
$ref: `#/components/schemas/${collection.name}`
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
list: {
|
|
26
|
+
method: "get",
|
|
27
|
+
responses
|
|
28
|
+
},
|
|
29
|
+
create: {
|
|
30
|
+
method: "post",
|
|
31
|
+
requestBody
|
|
32
|
+
},
|
|
33
|
+
get: {
|
|
34
|
+
method: "get",
|
|
35
|
+
responses
|
|
36
|
+
},
|
|
37
|
+
update: {
|
|
38
|
+
method: "put",
|
|
39
|
+
requestBody,
|
|
40
|
+
responses
|
|
41
|
+
},
|
|
42
|
+
destroy: {
|
|
43
|
+
method: "delete",
|
|
44
|
+
responses
|
|
45
|
+
},
|
|
46
|
+
add: {
|
|
47
|
+
method: "post",
|
|
48
|
+
requestBody,
|
|
49
|
+
responses
|
|
50
|
+
},
|
|
51
|
+
set: {
|
|
52
|
+
method: "post",
|
|
53
|
+
requestBody
|
|
54
|
+
},
|
|
55
|
+
remove: {
|
|
56
|
+
method: "delete",
|
|
57
|
+
responses
|
|
58
|
+
},
|
|
59
|
+
toggle: {
|
|
60
|
+
method: "post",
|
|
61
|
+
requestBody,
|
|
62
|
+
responses
|
|
63
|
+
},
|
|
64
|
+
move: {
|
|
65
|
+
method: "post",
|
|
66
|
+
requestBody
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const getInterfaceCollection = (options) => {
|
|
71
|
+
const accessors = {
|
|
72
|
+
// 常规 actions
|
|
73
|
+
list: "list",
|
|
74
|
+
create: "create",
|
|
75
|
+
get: "get",
|
|
76
|
+
update: "update",
|
|
77
|
+
delete: "destroy",
|
|
78
|
+
// associate 操作
|
|
79
|
+
add: "add",
|
|
80
|
+
set: "set",
|
|
81
|
+
remove: "remove",
|
|
82
|
+
toggle: "toggle",
|
|
83
|
+
move: "move",
|
|
84
|
+
...options.accessors || {}
|
|
85
|
+
};
|
|
86
|
+
const single = {
|
|
87
|
+
"/{resourceName}": [accessors.list, accessors.create, accessors.delete],
|
|
88
|
+
"/{resourceName}/{resourceIndex}": [accessors.get, accessors.update, accessors.delete],
|
|
89
|
+
"/{associatedName}/{associatedIndex}/{resourceName}": [
|
|
90
|
+
accessors.list,
|
|
91
|
+
accessors.create,
|
|
92
|
+
accessors.delete,
|
|
93
|
+
accessors.toggle,
|
|
94
|
+
accessors.add,
|
|
95
|
+
accessors.remove
|
|
96
|
+
],
|
|
97
|
+
"/{associatedName}/{associatedIndex}/{resourceName}/{resourceIndex}": [
|
|
98
|
+
accessors.get,
|
|
99
|
+
accessors.update,
|
|
100
|
+
accessors.delete,
|
|
101
|
+
accessors.remove,
|
|
102
|
+
accessors.toggle,
|
|
103
|
+
accessors.set,
|
|
104
|
+
accessors.move
|
|
105
|
+
]
|
|
106
|
+
};
|
|
107
|
+
return single;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.createDefaultActionSwagger = createDefaultActionSwagger;
|
|
111
|
+
exports.getInterfaceCollection = getInterfaceCollection;
|