@strapi/plugin-documentation 0.0.0-00a3f69152eb918683ed5c05bfed9c45495c0a87
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 +22 -0
- package/README.md +151 -0
- package/__mocks__/strapi.js +41 -0
- package/__tests__/build-component-schema.test.js +271 -0
- package/admin/src/components/FieldActionWrapper/index.js +14 -0
- package/admin/src/components/PluginIcon/index.js +12 -0
- package/admin/src/index.js +80 -0
- package/admin/src/pages/PluginPage/index.js +199 -0
- package/admin/src/pages/PluginPage/tests/index.test.js +873 -0
- package/admin/src/pages/PluginPage/tests/server.js +23 -0
- package/admin/src/pages/SettingsPage/index.js +181 -0
- package/admin/src/pages/SettingsPage/tests/index.test.js +612 -0
- package/admin/src/pages/SettingsPage/tests/server.js +18 -0
- package/admin/src/pages/utils/api.js +31 -0
- package/admin/src/pages/utils/schema.js +11 -0
- package/admin/src/pages/utils/useReactQuery.js +46 -0
- package/admin/src/permissions.js +19 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/translations/ar.json +20 -0
- package/admin/src/translations/cs.json +21 -0
- package/admin/src/translations/de.json +26 -0
- package/admin/src/translations/dk.json +39 -0
- package/admin/src/translations/en.json +39 -0
- package/admin/src/translations/es.json +39 -0
- package/admin/src/translations/fr.json +26 -0
- package/admin/src/translations/id.json +24 -0
- package/admin/src/translations/it.json +26 -0
- package/admin/src/translations/ko.json +39 -0
- package/admin/src/translations/ms.json +23 -0
- package/admin/src/translations/nl.json +21 -0
- package/admin/src/translations/pl.json +39 -0
- package/admin/src/translations/pt-BR.json +21 -0
- package/admin/src/translations/pt.json +21 -0
- package/admin/src/translations/ru.json +28 -0
- package/admin/src/translations/sk.json +24 -0
- package/admin/src/translations/sv.json +39 -0
- package/admin/src/translations/th.json +24 -0
- package/admin/src/translations/tr.json +20 -0
- package/admin/src/translations/uk.json +23 -0
- package/admin/src/translations/vi.json +24 -0
- package/admin/src/translations/zh-Hans.json +28 -0
- package/admin/src/translations/zh.json +39 -0
- package/admin/src/utils/getTrad.js +5 -0
- package/admin/src/utils/index.js +2 -0
- package/admin/src/utils/openWithNewTab.js +20 -0
- package/package.json +66 -0
- package/server/bootstrap.js +54 -0
- package/server/config/default-plugin-config.js +74 -0
- package/server/config/index.js +7 -0
- package/server/controllers/documentation.js +241 -0
- package/server/controllers/index.js +7 -0
- package/server/index.js +17 -0
- package/server/middlewares/documentation.js +25 -0
- package/server/middlewares/index.js +7 -0
- package/server/middlewares/restrict-access.js +24 -0
- package/server/public/index.html +70 -0
- package/server/public/login.html +145 -0
- package/server/register.js +11 -0
- package/server/routes/index.js +84 -0
- package/server/services/documentation.js +210 -0
- package/server/services/helpers/build-api-endpoint-path.js +185 -0
- package/server/services/helpers/build-component-schema.js +216 -0
- package/server/services/helpers/index.js +9 -0
- package/server/services/helpers/utils/clean-schema-attributes.js +235 -0
- package/server/services/helpers/utils/get-api-responses.js +105 -0
- package/server/services/helpers/utils/get-schema-data.js +32 -0
- package/server/services/helpers/utils/loop-content-type-names.js +53 -0
- package/server/services/helpers/utils/pascal-case.js +9 -0
- package/server/services/helpers/utils/query-params.js +95 -0
- package/server/services/helpers/utils/routes.js +10 -0
- package/server/services/index.js +7 -0
- package/strapi-admin.js +3 -0
- package/strapi-server.js +3 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const pascalCase = require('./pascal-case');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description - Builds the Swagger response object for a given api
|
|
7
|
+
*
|
|
8
|
+
* @param {object} name - Name of the api or plugin
|
|
9
|
+
* @param {object} route - The current route
|
|
10
|
+
* @param {boolean} isListOfEntities - Checks for a list of entitities
|
|
11
|
+
*
|
|
12
|
+
* @returns The Swagger responses
|
|
13
|
+
*/
|
|
14
|
+
const getApiResponse = ({
|
|
15
|
+
uniqueName,
|
|
16
|
+
route,
|
|
17
|
+
isListOfEntities = false,
|
|
18
|
+
isLocalizationPath = false,
|
|
19
|
+
}) => {
|
|
20
|
+
const getSchema = () => {
|
|
21
|
+
if (route.method === 'DELETE') {
|
|
22
|
+
return {
|
|
23
|
+
type: 'integer',
|
|
24
|
+
format: 'int64',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (isLocalizationPath) {
|
|
29
|
+
return { $ref: `#/components/schemas/${pascalCase(uniqueName)}LocalizationResponse` };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (isListOfEntities) {
|
|
33
|
+
return { $ref: `#/components/schemas/${pascalCase(uniqueName)}ListResponse` };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { $ref: `#/components/schemas/${pascalCase(uniqueName)}Response` };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const schema = getSchema();
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
responses: {
|
|
43
|
+
200: {
|
|
44
|
+
description: 'OK',
|
|
45
|
+
content: {
|
|
46
|
+
'application/json': {
|
|
47
|
+
schema,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
400: {
|
|
52
|
+
description: 'Bad Request',
|
|
53
|
+
content: {
|
|
54
|
+
'application/json': {
|
|
55
|
+
schema: {
|
|
56
|
+
$ref: '#/components/schemas/Error',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
401: {
|
|
62
|
+
description: 'Unauthorized',
|
|
63
|
+
content: {
|
|
64
|
+
'application/json': {
|
|
65
|
+
schema: {
|
|
66
|
+
$ref: '#/components/schemas/Error',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
403: {
|
|
72
|
+
description: 'Forbidden',
|
|
73
|
+
content: {
|
|
74
|
+
'application/json': {
|
|
75
|
+
schema: {
|
|
76
|
+
$ref: '#/components/schemas/Error',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
404: {
|
|
82
|
+
description: 'Not Found',
|
|
83
|
+
content: {
|
|
84
|
+
'application/json': {
|
|
85
|
+
schema: {
|
|
86
|
+
$ref: '#/components/schemas/Error',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
500: {
|
|
92
|
+
description: 'Internal Server Error',
|
|
93
|
+
content: {
|
|
94
|
+
'application/json': {
|
|
95
|
+
schema: {
|
|
96
|
+
$ref: '#/components/schemas/Error',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
module.exports = getApiResponse;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Determines the format of the data response
|
|
5
|
+
*
|
|
6
|
+
* @param {boolean} isListOfEntities - Checks for a multiple entities
|
|
7
|
+
* @param {object} attributes - The attributes found on a contentType
|
|
8
|
+
|
|
9
|
+
* @returns object | array of attributes
|
|
10
|
+
*/
|
|
11
|
+
module.exports = (isListOfEntities, attributes) => {
|
|
12
|
+
if (isListOfEntities) {
|
|
13
|
+
return {
|
|
14
|
+
type: 'array',
|
|
15
|
+
items: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
id: { type: 'number' },
|
|
19
|
+
attributes: { type: 'object', properties: attributes },
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
id: { type: 'number' },
|
|
29
|
+
attributes: { type: 'object', properties: attributes },
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description A reusable loop for building api endpoint paths and component schemas
|
|
7
|
+
*
|
|
8
|
+
* @param {object} api - Api information to pass to the callback
|
|
9
|
+
* @param {function} callback - Logic to execute for the given api
|
|
10
|
+
*
|
|
11
|
+
* @returns {object}
|
|
12
|
+
*/
|
|
13
|
+
const loopContentTypeNames = (api, callback) => {
|
|
14
|
+
let result = {};
|
|
15
|
+
for (const contentTypeName of api.ctNames) {
|
|
16
|
+
// Get the attributes found on the api's contentType
|
|
17
|
+
const uid = `${api.getter}::${api.name}.${contentTypeName}`;
|
|
18
|
+
const { attributes, info: contentTypeInfo } = strapi.contentType(uid);
|
|
19
|
+
|
|
20
|
+
// Get the routes for the current api
|
|
21
|
+
const routeInfo =
|
|
22
|
+
api.getter === 'plugin'
|
|
23
|
+
? strapi.plugin(api.name).routes['content-api']
|
|
24
|
+
: strapi.api[api.name].routes[contentTypeName];
|
|
25
|
+
|
|
26
|
+
// Continue to next iteration if routeInfo is undefined
|
|
27
|
+
if (!routeInfo) continue;
|
|
28
|
+
|
|
29
|
+
// Uppercase the first letter of the api name
|
|
30
|
+
const apiName = _.upperFirst(api.name);
|
|
31
|
+
|
|
32
|
+
// Create a unique name if the api name and contentType name don't match
|
|
33
|
+
const uniqueName =
|
|
34
|
+
api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;
|
|
35
|
+
|
|
36
|
+
const apiInfo = {
|
|
37
|
+
...api,
|
|
38
|
+
routeInfo,
|
|
39
|
+
attributes,
|
|
40
|
+
uniqueName,
|
|
41
|
+
contentTypeInfo,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
result = {
|
|
45
|
+
...result,
|
|
46
|
+
...callback(apiInfo),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = loopContentTypeNames;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = [
|
|
4
|
+
{
|
|
5
|
+
name: 'sort',
|
|
6
|
+
in: 'query',
|
|
7
|
+
description: 'Sort by attributes ascending (asc) or descending (desc)',
|
|
8
|
+
deprecated: false,
|
|
9
|
+
required: false,
|
|
10
|
+
schema: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'pagination[withCount]',
|
|
16
|
+
in: 'query',
|
|
17
|
+
description: 'Retun page/pageSize (default: true)',
|
|
18
|
+
deprecated: false,
|
|
19
|
+
required: false,
|
|
20
|
+
schema: {
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'pagination[page]',
|
|
26
|
+
in: 'query',
|
|
27
|
+
description: 'Page number (default: 0)',
|
|
28
|
+
deprecated: false,
|
|
29
|
+
required: false,
|
|
30
|
+
schema: {
|
|
31
|
+
type: 'integer',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'pagination[pageSize]',
|
|
36
|
+
in: 'query',
|
|
37
|
+
description: 'Page size (default: 25)',
|
|
38
|
+
deprecated: false,
|
|
39
|
+
required: false,
|
|
40
|
+
schema: {
|
|
41
|
+
type: 'integer',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'pagination[start]',
|
|
46
|
+
in: 'query',
|
|
47
|
+
description: 'Offset value (default: 0)',
|
|
48
|
+
deprecated: false,
|
|
49
|
+
required: false,
|
|
50
|
+
schema: {
|
|
51
|
+
type: 'integer',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'pagination[limit]',
|
|
56
|
+
in: 'query',
|
|
57
|
+
description: 'Number of entities to return (default: 25)',
|
|
58
|
+
deprecated: false,
|
|
59
|
+
required: false,
|
|
60
|
+
schema: {
|
|
61
|
+
type: 'integer',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'fields',
|
|
66
|
+
in: 'query',
|
|
67
|
+
description: 'Fields to return (ex: title,author)',
|
|
68
|
+
deprecated: false,
|
|
69
|
+
required: false,
|
|
70
|
+
schema: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'populate',
|
|
76
|
+
in: 'query',
|
|
77
|
+
description: 'Relations to return',
|
|
78
|
+
deprecated: false,
|
|
79
|
+
required: false,
|
|
80
|
+
schema: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'filters',
|
|
86
|
+
in: 'query',
|
|
87
|
+
description: 'Filters to apply',
|
|
88
|
+
deprecated: false,
|
|
89
|
+
required: false,
|
|
90
|
+
schema: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
},
|
|
93
|
+
style: 'deepObject',
|
|
94
|
+
},
|
|
95
|
+
];
|
package/strapi-admin.js
ADDED
package/strapi-server.js
ADDED