@strapi/plugin-documentation 5.0.0-beta.0 → 5.0.0-beta.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/README.md +0 -1
- package/dist/_chunks/{index-7xstUX8_.mjs → App-ig-uE4do.mjs} +48 -14
- package/dist/_chunks/App-ig-uE4do.mjs.map +1 -0
- package/dist/_chunks/{index-D1KkfApT.js → App-o4uH8gaQ.js} +73 -20
- package/dist/_chunks/App-o4uH8gaQ.js.map +1 -0
- package/dist/_chunks/{index-VpLAJXMs.mjs → Settings-3hsPOP_b.mjs} +64 -33
- package/dist/_chunks/Settings-3hsPOP_b.mjs.map +1 -0
- package/dist/_chunks/{index-NbPCucJl.js → Settings-XmOzLTUn.js} +69 -37
- package/dist/_chunks/Settings-XmOzLTUn.js.map +1 -0
- package/dist/_chunks/getTrad-bnElvR8_.js +5 -0
- package/dist/_chunks/getTrad-bnElvR8_.js.map +1 -0
- package/dist/_chunks/getTrad-md7Tjpcv.mjs +6 -0
- package/dist/_chunks/getTrad-md7Tjpcv.mjs.map +1 -0
- package/{server/public/index.html → dist/_chunks/index-MKWIGajW.mjs} +9 -4
- package/dist/_chunks/index-MKWIGajW.mjs.map +1 -0
- package/dist/_chunks/index-WbbYm9_u.js +75 -0
- package/dist/_chunks/index-WbbYm9_u.js.map +1 -0
- package/dist/_chunks/{index-NvJ4m2q5.mjs → index-jpDwTC-Q.mjs} +121 -117
- package/dist/_chunks/index-jpDwTC-Q.mjs.map +1 -0
- package/dist/_chunks/{index-r7HsQTou.js → index-vNbIS1u2.js} +119 -115
- package/dist/_chunks/index-vNbIS1u2.js.map +1 -0
- package/dist/_chunks/login-HAajOKpu.js +150 -0
- package/dist/_chunks/login-HAajOKpu.js.map +1 -0
- package/{server/public/login.html → dist/_chunks/login-slUa679p.mjs} +6 -1
- package/dist/_chunks/login-slUa679p.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/src/components/SettingsForm.d.ts +8 -0
- package/dist/admin/src/constants.d.ts +18 -0
- package/dist/admin/src/index.d.ts +14 -0
- package/dist/admin/src/pages/App.d.ts +2 -0
- package/dist/admin/src/pages/Settings.d.ts +2 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/services/api.d.ts +25 -0
- package/dist/admin/src/types.d.ts +16 -0
- package/dist/admin/src/utils/baseQuery.d.ts +20 -0
- package/dist/admin/src/utils/getTrad.d.ts +1 -0
- package/dist/admin/src/utils/index.d.ts +2 -0
- package/dist/admin/src/utils/prefixPluginTranslations.d.ts +2 -0
- package/dist/server/index.js +1263 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +1238 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/bootstrap.d.ts.map +1 -0
- package/dist/server/src/config/default-plugin-config.d.ts +3 -0
- package/dist/server/src/config/default-plugin-config.d.ts.map +1 -0
- package/dist/server/src/config/index.d.ts +4 -0
- package/dist/server/src/config/index.d.ts.map +1 -0
- package/dist/server/src/controllers/documentation.d.ts +12 -0
- package/dist/server/src/controllers/documentation.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +14 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +91 -0
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/middlewares/documentation.d.ts +5 -0
- package/dist/server/src/middlewares/documentation.d.ts.map +1 -0
- package/dist/server/src/middlewares/restrict-access.d.ts +4 -0
- package/dist/server/src/middlewares/restrict-access.d.ts.map +1 -0
- package/dist/server/src/register.d.ts +5 -0
- package/dist/server/src/register.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts +36 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/services/__mocks__/mock-content-types.d.ts +449 -0
- package/dist/server/src/services/__mocks__/mock-content-types.d.ts.map +1 -0
- package/dist/server/src/services/__mocks__/mock-strapi-data.d.ts +592 -0
- package/dist/server/src/services/__mocks__/mock-strapi-data.d.ts.map +1 -0
- package/dist/server/src/services/documentation.d.ts +36 -0
- package/dist/server/src/services/documentation.d.ts.map +1 -0
- package/dist/server/src/services/helpers/build-api-endpoint-path.d.ts +7 -0
- package/dist/server/src/services/helpers/build-api-endpoint-path.d.ts.map +1 -0
- package/dist/server/src/services/helpers/build-component-schema.d.ts +4 -0
- package/dist/server/src/services/helpers/build-component-schema.d.ts.map +1 -0
- package/dist/server/src/services/helpers/index.d.ts +4 -0
- package/dist/server/src/services/helpers/index.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts +15 -0
- package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/get-api-responses.d.ts +15 -0
- package/dist/server/src/services/helpers/utils/get-api-responses.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/get-schema-data.d.ts +12 -0
- package/dist/server/src/services/helpers/utils/get-schema-data.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts +7 -0
- package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/pascal-case.d.ts +3 -0
- package/dist/server/src/services/helpers/utils/pascal-case.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/query-params.d.ts +4 -0
- package/dist/server/src/services/helpers/utils/query-params.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/routes.d.ts +3 -0
- package/dist/server/src/services/helpers/utils/routes.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +43 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/override.d.ts +21 -0
- package/dist/server/src/services/override.d.ts.map +1 -0
- package/dist/server/src/services/utils/get-plugins-that-need-documentation.d.ts +4 -0
- package/dist/server/src/services/utils/get-plugins-that-need-documentation.d.ts.map +1 -0
- package/dist/server/src/types.d.ts +28 -0
- package/dist/server/src/types.d.ts.map +1 -0
- package/dist/server/src/utils.d.ts +12 -0
- package/dist/server/src/utils.d.ts.map +1 -0
- package/package.json +33 -15
- package/strapi-server.js +1 -1
- package/.eslintignore +0 -1
- package/.eslintrc +0 -17
- package/admin/src/constants.js +0 -17
- package/admin/src/hooks/useDocumentation.js +0 -81
- package/admin/src/index.js +0 -62
- package/admin/src/pages/PluginPage/index.jsx +0 -212
- package/admin/src/pages/PluginPage/tests/index.test.jsx +0 -160
- package/admin/src/pages/SettingsPage/index.jsx +0 -202
- package/admin/src/pages/SettingsPage/tests/index.test.jsx +0 -72
- package/admin/src/pluginId.js +0 -5
- package/admin/src/translations/ar.json +0 -20
- package/admin/src/translations/cs.json +0 -21
- package/admin/src/translations/de.json +0 -26
- package/admin/src/translations/dk.json +0 -39
- package/admin/src/translations/en.json +0 -39
- package/admin/src/translations/es.json +0 -39
- package/admin/src/translations/fr.json +0 -26
- package/admin/src/translations/id.json +0 -24
- package/admin/src/translations/it.json +0 -26
- package/admin/src/translations/ko.json +0 -39
- package/admin/src/translations/ms.json +0 -23
- package/admin/src/translations/nl.json +0 -21
- package/admin/src/translations/pl.json +0 -39
- package/admin/src/translations/pt-BR.json +0 -21
- package/admin/src/translations/pt.json +0 -21
- package/admin/src/translations/ru.json +0 -39
- package/admin/src/translations/sk.json +0 -24
- package/admin/src/translations/sv.json +0 -39
- package/admin/src/translations/th.json +0 -24
- package/admin/src/translations/tr.json +0 -39
- package/admin/src/translations/uk.json +0 -23
- package/admin/src/translations/vi.json +0 -24
- package/admin/src/translations/zh-Hans.json +0 -28
- package/admin/src/translations/zh.json +0 -39
- package/admin/src/utils/getTrad.js +0 -5
- package/admin/src/utils/index.js +0 -2
- package/admin/src/utils/prefixPluginTranslations.js +0 -13
- package/dist/_chunks/index-7xstUX8_.mjs.map +0 -1
- package/dist/_chunks/index-D1KkfApT.js.map +0 -1
- package/dist/_chunks/index-NbPCucJl.js.map +0 -1
- package/dist/_chunks/index-NvJ4m2q5.mjs.map +0 -1
- package/dist/_chunks/index-VpLAJXMs.mjs.map +0 -1
- package/dist/_chunks/index-r7HsQTou.js.map +0 -1
- package/dist/_chunks/useDocumentation-6Ks-_Ms6.mjs +0 -68
- package/dist/_chunks/useDocumentation-6Ks-_Ms6.mjs.map +0 -1
- package/dist/_chunks/useDocumentation-S0e4mU-U.js +0 -67
- package/dist/_chunks/useDocumentation-S0e4mU-U.js.map +0 -1
- package/jest.config.front.js +0 -7
- package/jest.config.js +0 -6
- package/packup.config.ts +0 -22
- package/server/bootstrap.js +0 -54
- package/server/config/default-plugin-config.js +0 -35
- package/server/config/index.js +0 -7
- package/server/controllers/documentation.js +0 -241
- package/server/controllers/index.js +0 -7
- package/server/index.js +0 -17
- package/server/middlewares/documentation.js +0 -25
- package/server/middlewares/index.js +0 -7
- package/server/middlewares/restrict-access.js +0 -24
- package/server/register.js +0 -11
- package/server/routes/index.js +0 -84
- package/server/services/__mocks__/mock-content-types.js +0 -264
- package/server/services/__mocks__/mock-strapi-data.js +0 -183
- package/server/services/__tests__/build-component-schema.test.js +0 -761
- package/server/services/__tests__/documentation.test.js +0 -481
- package/server/services/__tests__/override.test.js +0 -85
- package/server/services/documentation.js +0 -246
- package/server/services/helpers/build-api-endpoint-path.js +0 -186
- package/server/services/helpers/build-component-schema.js +0 -254
- package/server/services/helpers/index.js +0 -9
- package/server/services/helpers/utils/clean-schema-attributes.js +0 -246
- package/server/services/helpers/utils/get-api-responses.js +0 -105
- package/server/services/helpers/utils/get-schema-data.js +0 -32
- package/server/services/helpers/utils/loop-content-type-names.js +0 -55
- package/server/services/helpers/utils/pascal-case.js +0 -9
- package/server/services/helpers/utils/query-params.js +0 -105
- package/server/services/helpers/utils/routes.js +0 -10
- package/server/services/index.js +0 -9
- package/server/services/override.js +0 -52
- package/server/services/utils/default-openapi-components.js +0 -40
- package/server/services/utils/get-plugins-that-need-documentation.js +0 -24
- package/tests/server.js +0 -37
- package/tests/setup.js +0 -15
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const getSchemaData = require('./get-schema-data');
|
|
5
|
-
const pascalCase = require('./pascal-case');
|
|
6
|
-
/**
|
|
7
|
-
* @description - Converts types found on attributes to OpenAPI acceptable data types
|
|
8
|
-
*
|
|
9
|
-
* @param {object} attributes - The attributes found on a contentType
|
|
10
|
-
* @param {{ typeMap: Map, isRequest: boolean, didAddStrapiComponentsToSchemas: function, componentSchemaRefName: string }} opts
|
|
11
|
-
* @returns Attributes using OpenAPI acceptable data types
|
|
12
|
-
*/
|
|
13
|
-
const cleanSchemaAttributes = (
|
|
14
|
-
attributes,
|
|
15
|
-
{
|
|
16
|
-
typeMap = new Map(),
|
|
17
|
-
isRequest = false,
|
|
18
|
-
didAddStrapiComponentsToSchemas = () => {},
|
|
19
|
-
componentSchemaRefName = '',
|
|
20
|
-
} = {}
|
|
21
|
-
) => {
|
|
22
|
-
const attributesCopy = _.cloneDeep(attributes);
|
|
23
|
-
|
|
24
|
-
for (const prop of Object.keys(attributesCopy)) {
|
|
25
|
-
const attribute = attributesCopy[prop];
|
|
26
|
-
if (attribute.default) {
|
|
27
|
-
delete attributesCopy[prop].default;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
switch (attribute.type) {
|
|
31
|
-
case 'password': {
|
|
32
|
-
if (!isRequest) {
|
|
33
|
-
delete attributesCopy[prop];
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
attributesCopy[prop] = { type: 'string', format: 'password', example: '*******' };
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
case 'email': {
|
|
41
|
-
attributesCopy[prop] = { type: 'string', format: 'email' };
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
case 'string':
|
|
45
|
-
case 'text':
|
|
46
|
-
case 'richtext': {
|
|
47
|
-
attributesCopy[prop] = { type: 'string' };
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case 'timestamp': {
|
|
51
|
-
attributesCopy[prop] = { type: 'string', format: 'timestamp', example: Date.now() };
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case 'time': {
|
|
55
|
-
attributesCopy[prop] = { type: 'string', format: 'time', example: '12:54.000' };
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case 'date': {
|
|
59
|
-
attributesCopy[prop] = { type: 'string', format: 'date' };
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
case 'datetime': {
|
|
63
|
-
attributesCopy[prop] = { type: 'string', format: 'date-time' };
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case 'boolean': {
|
|
67
|
-
attributesCopy[prop] = { type: 'boolean' };
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
case 'enumeration': {
|
|
71
|
-
attributesCopy[prop] = { type: 'string', enum: attribute.enum };
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case 'decimal':
|
|
75
|
-
case 'float': {
|
|
76
|
-
attributesCopy[prop] = { type: 'number', format: 'float' };
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case 'integer': {
|
|
80
|
-
attributesCopy[prop] = { type: 'integer' };
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
case 'biginteger': {
|
|
84
|
-
attributesCopy[prop] = { type: 'string', pattern: '^\\d*$', example: '123456789' };
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case 'json':
|
|
88
|
-
case 'blocks': {
|
|
89
|
-
attributesCopy[prop] = {};
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
case 'uid': {
|
|
93
|
-
attributesCopy[prop] = { type: 'string' };
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
case 'component': {
|
|
97
|
-
const componentAttributes = strapi.components[attribute.component].attributes;
|
|
98
|
-
const rawComponentSchema = {
|
|
99
|
-
type: 'object',
|
|
100
|
-
properties: {
|
|
101
|
-
...(isRequest ? {} : { id: { type: 'number' } }),
|
|
102
|
-
...cleanSchemaAttributes(componentAttributes, {
|
|
103
|
-
typeMap,
|
|
104
|
-
isRequest,
|
|
105
|
-
}),
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
const refComponentSchema = {
|
|
109
|
-
$ref: `#/components/schemas/${pascalCase(attribute.component)}Component`,
|
|
110
|
-
};
|
|
111
|
-
const componentExists = didAddStrapiComponentsToSchemas(
|
|
112
|
-
`${pascalCase(attribute.component)}Component`,
|
|
113
|
-
rawComponentSchema
|
|
114
|
-
);
|
|
115
|
-
const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;
|
|
116
|
-
if (attribute.repeatable) {
|
|
117
|
-
attributesCopy[prop] = {
|
|
118
|
-
type: 'array',
|
|
119
|
-
items: finalComponentSchema,
|
|
120
|
-
};
|
|
121
|
-
} else {
|
|
122
|
-
attributesCopy[prop] = finalComponentSchema;
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
case 'dynamiczone': {
|
|
127
|
-
const components = attribute.components.map((component) => {
|
|
128
|
-
const componentAttributes = strapi.components[component].attributes;
|
|
129
|
-
const rawComponentSchema = {
|
|
130
|
-
type: 'object',
|
|
131
|
-
properties: {
|
|
132
|
-
...(isRequest ? {} : { id: { type: 'number' } }),
|
|
133
|
-
__component: { type: 'string' },
|
|
134
|
-
...cleanSchemaAttributes(componentAttributes, {
|
|
135
|
-
typeMap,
|
|
136
|
-
isRequest,
|
|
137
|
-
didAddStrapiComponentsToSchemas,
|
|
138
|
-
}),
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
const refComponentSchema = {
|
|
142
|
-
$ref: `#/components/schemas/${pascalCase(component)}Component`,
|
|
143
|
-
};
|
|
144
|
-
const componentExists = didAddStrapiComponentsToSchemas(
|
|
145
|
-
`${pascalCase(component)}Component`,
|
|
146
|
-
rawComponentSchema
|
|
147
|
-
);
|
|
148
|
-
const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;
|
|
149
|
-
return finalComponentSchema;
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
attributesCopy[prop] = {
|
|
153
|
-
type: 'array',
|
|
154
|
-
items: {
|
|
155
|
-
anyOf: components,
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
case 'media': {
|
|
161
|
-
const imageAttributes = strapi.contentType('plugin::upload.file').attributes;
|
|
162
|
-
const isListOfEntities = attribute.multiple;
|
|
163
|
-
|
|
164
|
-
if (isRequest) {
|
|
165
|
-
const oneOfType = {
|
|
166
|
-
oneOf: [{ type: 'integer' }, { type: 'string' }],
|
|
167
|
-
example: 'string or id',
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
attributesCopy[prop] = isListOfEntities ? { type: 'array', items: oneOfType } : oneOfType;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
attributesCopy[prop] = {
|
|
175
|
-
type: 'object',
|
|
176
|
-
properties: {
|
|
177
|
-
data: getSchemaData(
|
|
178
|
-
isListOfEntities,
|
|
179
|
-
cleanSchemaAttributes(imageAttributes, { typeMap })
|
|
180
|
-
),
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
case 'relation': {
|
|
187
|
-
const isListOfEntities = attribute.relation.includes('ToMany');
|
|
188
|
-
|
|
189
|
-
if (isRequest) {
|
|
190
|
-
const oneOfType = {
|
|
191
|
-
oneOf: [{ type: 'integer' }, { type: 'string' }],
|
|
192
|
-
example: 'string or id',
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
attributesCopy[prop] = isListOfEntities ? { type: 'array', items: oneOfType } : oneOfType;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (prop === 'localizations') {
|
|
200
|
-
attributesCopy[prop] = {
|
|
201
|
-
type: 'object',
|
|
202
|
-
properties: {
|
|
203
|
-
data: {
|
|
204
|
-
type: 'array',
|
|
205
|
-
items: componentSchemaRefName.length
|
|
206
|
-
? { $ref: `${componentSchemaRefName}ListResponseDataItemLocalized` }
|
|
207
|
-
: {},
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (!attribute.target || typeMap.has(attribute.target)) {
|
|
215
|
-
attributesCopy[prop] = {
|
|
216
|
-
type: 'object',
|
|
217
|
-
properties: { data: getSchemaData(isListOfEntities, {}) },
|
|
218
|
-
};
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
typeMap.set(attribute.target, true);
|
|
223
|
-
const targetAttributes = strapi.contentType(attribute.target).attributes;
|
|
224
|
-
|
|
225
|
-
attributesCopy[prop] = {
|
|
226
|
-
type: 'object',
|
|
227
|
-
properties: {
|
|
228
|
-
data: getSchemaData(
|
|
229
|
-
isListOfEntities,
|
|
230
|
-
cleanSchemaAttributes(targetAttributes, { typeMap, isRequest })
|
|
231
|
-
),
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
default: {
|
|
238
|
-
throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return attributesCopy;
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
module.exports = cleanSchemaAttributes;
|
|
@@ -1,105 +0,0 @@
|
|
|
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;
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
|
|
19
|
-
const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid);
|
|
20
|
-
|
|
21
|
-
// Get the routes for the current api
|
|
22
|
-
const routeInfo =
|
|
23
|
-
api.getter === 'plugin'
|
|
24
|
-
? strapi.plugin(api.name).routes['content-api']
|
|
25
|
-
: strapi.api[api.name].routes[contentTypeName];
|
|
26
|
-
|
|
27
|
-
// Continue to next iteration if routeInfo is undefined
|
|
28
|
-
if (!routeInfo) continue;
|
|
29
|
-
|
|
30
|
-
// Uppercase the first letter of the api name
|
|
31
|
-
const apiName = _.upperFirst(api.name);
|
|
32
|
-
|
|
33
|
-
// Create a unique name if the api name and contentType name don't match
|
|
34
|
-
const uniqueName =
|
|
35
|
-
api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;
|
|
36
|
-
|
|
37
|
-
const apiInfo = {
|
|
38
|
-
...api,
|
|
39
|
-
routeInfo,
|
|
40
|
-
attributes,
|
|
41
|
-
uniqueName,
|
|
42
|
-
contentTypeInfo,
|
|
43
|
-
kind,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
result = {
|
|
47
|
-
...result,
|
|
48
|
-
...callback(apiInfo),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return result;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
module.exports = loopContentTypeNames;
|
|
@@ -1,105 +0,0 @@
|
|
|
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: 'Return 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
|
-
{
|
|
96
|
-
name: 'locale',
|
|
97
|
-
in: 'query',
|
|
98
|
-
description: 'Locale to apply',
|
|
99
|
-
deprecated: false,
|
|
100
|
-
required: false,
|
|
101
|
-
schema: {
|
|
102
|
-
type: 'string',
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
];
|
package/server/services/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { getPluginsThatNeedDocumentation } = require('./utils/get-plugins-that-need-documentation');
|
|
4
|
-
|
|
5
|
-
module.exports = ({ strapi }) => {
|
|
6
|
-
const registeredOverrides = [];
|
|
7
|
-
const excludedFromGeneration = [];
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
registeredOverrides,
|
|
11
|
-
excludedFromGeneration,
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {(string | string[])} api - The name of the api or and array of apis to exclude from generation
|
|
15
|
-
*/
|
|
16
|
-
excludeFromGeneration(api) {
|
|
17
|
-
if (Array.isArray(api)) {
|
|
18
|
-
excludedFromGeneration.push(...api);
|
|
19
|
-
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
excludedFromGeneration.push(api);
|
|
24
|
-
},
|
|
25
|
-
/**
|
|
26
|
-
* @TODO pluginOrigin should be required in next major release
|
|
27
|
-
* @param {object} doc - The openapi specifcation to override
|
|
28
|
-
* @param {object} options - The options to override the documentation
|
|
29
|
-
* @param {(string | undefined)} options.pluginOrigin - The name of the plugin that is overriding the documentation
|
|
30
|
-
* @param {string[]} options.excludeFromGeneration - The list of apis or plugins to exclude from generation
|
|
31
|
-
*/
|
|
32
|
-
registerOverride(override, { pluginOrigin, excludeFromGeneration = [] } = {}) {
|
|
33
|
-
const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(
|
|
34
|
-
strapi.config.get('plugin::documentation')
|
|
35
|
-
);
|
|
36
|
-
// Don't apply the override if the plugin is not in the list of plugins that need documentation
|
|
37
|
-
if (pluginOrigin && !pluginsThatNeedDocumentation.includes(pluginOrigin)) return;
|
|
38
|
-
|
|
39
|
-
if (excludeFromGeneration.length) {
|
|
40
|
-
this.excludeFromGeneration(excludeFromGeneration);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let overrideToRegister = override;
|
|
44
|
-
// Parse yaml if we receive a string
|
|
45
|
-
if (typeof override === 'string') {
|
|
46
|
-
overrideToRegister = require('yaml').parse(overrideToRegister);
|
|
47
|
-
}
|
|
48
|
-
// receive an object we can register it directly
|
|
49
|
-
registeredOverrides.push(overrideToRegister);
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
securitySchemes: {
|
|
5
|
-
bearerAuth: {
|
|
6
|
-
type: 'http',
|
|
7
|
-
scheme: 'bearer',
|
|
8
|
-
bearerFormat: 'JWT',
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
schemas: {
|
|
12
|
-
Error: {
|
|
13
|
-
type: 'object',
|
|
14
|
-
required: ['error'],
|
|
15
|
-
properties: {
|
|
16
|
-
data: {
|
|
17
|
-
nullable: true,
|
|
18
|
-
oneOf: [{ type: 'object' }, { type: 'array', items: { type: 'object' } }],
|
|
19
|
-
},
|
|
20
|
-
error: {
|
|
21
|
-
type: 'object',
|
|
22
|
-
properties: {
|
|
23
|
-
status: {
|
|
24
|
-
type: 'integer',
|
|
25
|
-
},
|
|
26
|
-
name: {
|
|
27
|
-
type: 'string',
|
|
28
|
-
},
|
|
29
|
-
message: {
|
|
30
|
-
type: 'string',
|
|
31
|
-
},
|
|
32
|
-
details: {
|
|
33
|
-
type: 'object',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const getPluginsThatNeedDocumentation = (config) => {
|
|
4
|
-
// Default plugins that need documentation generated
|
|
5
|
-
const defaultPlugins = ['upload', 'users-permissions'];
|
|
6
|
-
|
|
7
|
-
// User specified plugins that need documentation generated
|
|
8
|
-
const userPluginsConfig = config['x-strapi-config'].plugins;
|
|
9
|
-
|
|
10
|
-
if (userPluginsConfig === null) {
|
|
11
|
-
// The user hasn't specified any plugins to document, use the defaults
|
|
12
|
-
return defaultPlugins;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (userPluginsConfig.length) {
|
|
16
|
-
// The user has specified certain plugins to document, use them
|
|
17
|
-
return userPluginsConfig;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// The user has specified that no plugins should be documented
|
|
21
|
-
return [];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
module.exports = { getPluginsThatNeedDocumentation };
|