@strapi/plugin-documentation 5.0.0-beta.0 → 5.0.0-beta.2

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 (184) hide show
  1. package/README.md +0 -1
  2. package/dist/_chunks/{index-D1KkfApT.js → App-Dsqz1mTz.js} +74 -22
  3. package/dist/_chunks/App-Dsqz1mTz.js.map +1 -0
  4. package/dist/_chunks/{index-7xstUX8_.mjs → App-mrzd5Xqj.mjs} +49 -16
  5. package/dist/_chunks/App-mrzd5Xqj.mjs.map +1 -0
  6. package/dist/_chunks/{index-VpLAJXMs.mjs → Settings-8v7IbdtY.mjs} +64 -33
  7. package/dist/_chunks/Settings-8v7IbdtY.mjs.map +1 -0
  8. package/dist/_chunks/{index-NbPCucJl.js → Settings-wdLQpouP.js} +69 -37
  9. package/dist/_chunks/Settings-wdLQpouP.js.map +1 -0
  10. package/dist/_chunks/getTrad-SeEDjZbP.mjs +6 -0
  11. package/dist/_chunks/getTrad-SeEDjZbP.mjs.map +1 -0
  12. package/dist/_chunks/getTrad-xlpeC9HP.js +5 -0
  13. package/dist/_chunks/getTrad-xlpeC9HP.js.map +1 -0
  14. package/{server/public/index.html → dist/_chunks/index-MKWIGajW.mjs} +9 -4
  15. package/dist/_chunks/index-MKWIGajW.mjs.map +1 -0
  16. package/dist/_chunks/index-WbbYm9_u.js +75 -0
  17. package/dist/_chunks/index-WbbYm9_u.js.map +1 -0
  18. package/dist/_chunks/{index-r7HsQTou.js → index-_yYcImHU.js} +126 -119
  19. package/dist/_chunks/index-_yYcImHU.js.map +1 -0
  20. package/dist/_chunks/{index-NvJ4m2q5.mjs → index-mXCyE3EQ.mjs} +128 -121
  21. package/dist/_chunks/index-mXCyE3EQ.mjs.map +1 -0
  22. package/dist/_chunks/login-HAajOKpu.js +150 -0
  23. package/dist/_chunks/login-HAajOKpu.js.map +1 -0
  24. package/{server/public/login.html → dist/_chunks/login-slUa679p.mjs} +6 -1
  25. package/dist/_chunks/login-slUa679p.mjs.map +1 -0
  26. package/dist/admin/index.js +1 -1
  27. package/dist/admin/index.mjs +2 -2
  28. package/dist/admin/src/components/SettingsForm.d.ts +8 -0
  29. package/dist/admin/src/constants.d.ts +18 -0
  30. package/dist/admin/src/index.d.ts +14 -0
  31. package/dist/admin/src/pages/App.d.ts +2 -0
  32. package/dist/admin/src/pages/Settings.d.ts +2 -0
  33. package/dist/admin/src/pluginId.d.ts +1 -0
  34. package/dist/admin/src/services/api.d.ts +25 -0
  35. package/dist/admin/src/types.d.ts +16 -0
  36. package/dist/admin/src/utils/baseQuery.d.ts +20 -0
  37. package/dist/admin/src/utils/getTrad.d.ts +1 -0
  38. package/dist/admin/src/utils/index.d.ts +2 -0
  39. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +2 -0
  40. package/dist/server/index.js +1263 -0
  41. package/dist/server/index.js.map +1 -0
  42. package/dist/server/index.mjs +1238 -0
  43. package/dist/server/index.mjs.map +1 -0
  44. package/dist/server/src/bootstrap.d.ts +5 -0
  45. package/dist/server/src/bootstrap.d.ts.map +1 -0
  46. package/dist/server/src/config/default-plugin-config.d.ts +3 -0
  47. package/dist/server/src/config/default-plugin-config.d.ts.map +1 -0
  48. package/dist/server/src/config/index.d.ts +4 -0
  49. package/dist/server/src/config/index.d.ts.map +1 -0
  50. package/dist/server/src/controllers/documentation.d.ts +12 -0
  51. package/dist/server/src/controllers/documentation.d.ts.map +1 -0
  52. package/dist/server/src/controllers/index.d.ts +14 -0
  53. package/dist/server/src/controllers/index.d.ts.map +1 -0
  54. package/dist/server/src/index.d.ts +91 -0
  55. package/dist/server/src/index.d.ts.map +1 -0
  56. package/dist/server/src/middlewares/documentation.d.ts +5 -0
  57. package/dist/server/src/middlewares/documentation.d.ts.map +1 -0
  58. package/dist/server/src/middlewares/restrict-access.d.ts +4 -0
  59. package/dist/server/src/middlewares/restrict-access.d.ts.map +1 -0
  60. package/dist/server/src/register.d.ts +5 -0
  61. package/dist/server/src/register.d.ts.map +1 -0
  62. package/dist/server/src/routes/index.d.ts +36 -0
  63. package/dist/server/src/routes/index.d.ts.map +1 -0
  64. package/dist/server/src/services/__mocks__/mock-content-types.d.ts +449 -0
  65. package/dist/server/src/services/__mocks__/mock-content-types.d.ts.map +1 -0
  66. package/dist/server/src/services/__mocks__/mock-strapi-data.d.ts +592 -0
  67. package/dist/server/src/services/__mocks__/mock-strapi-data.d.ts.map +1 -0
  68. package/dist/server/src/services/documentation.d.ts +36 -0
  69. package/dist/server/src/services/documentation.d.ts.map +1 -0
  70. package/dist/server/src/services/helpers/build-api-endpoint-path.d.ts +7 -0
  71. package/dist/server/src/services/helpers/build-api-endpoint-path.d.ts.map +1 -0
  72. package/dist/server/src/services/helpers/build-component-schema.d.ts +4 -0
  73. package/dist/server/src/services/helpers/build-component-schema.d.ts.map +1 -0
  74. package/dist/server/src/services/helpers/index.d.ts +4 -0
  75. package/dist/server/src/services/helpers/index.d.ts.map +1 -0
  76. package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts +15 -0
  77. package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts.map +1 -0
  78. package/dist/server/src/services/helpers/utils/get-api-responses.d.ts +15 -0
  79. package/dist/server/src/services/helpers/utils/get-api-responses.d.ts.map +1 -0
  80. package/dist/server/src/services/helpers/utils/get-schema-data.d.ts +12 -0
  81. package/dist/server/src/services/helpers/utils/get-schema-data.d.ts.map +1 -0
  82. package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts +7 -0
  83. package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts.map +1 -0
  84. package/dist/server/src/services/helpers/utils/pascal-case.d.ts +3 -0
  85. package/dist/server/src/services/helpers/utils/pascal-case.d.ts.map +1 -0
  86. package/dist/server/src/services/helpers/utils/query-params.d.ts +4 -0
  87. package/dist/server/src/services/helpers/utils/query-params.d.ts.map +1 -0
  88. package/dist/server/src/services/helpers/utils/routes.d.ts +3 -0
  89. package/dist/server/src/services/helpers/utils/routes.d.ts.map +1 -0
  90. package/dist/server/src/services/index.d.ts +43 -0
  91. package/dist/server/src/services/index.d.ts.map +1 -0
  92. package/dist/server/src/services/override.d.ts +21 -0
  93. package/dist/server/src/services/override.d.ts.map +1 -0
  94. package/dist/server/src/services/utils/get-plugins-that-need-documentation.d.ts +4 -0
  95. package/dist/server/src/services/utils/get-plugins-that-need-documentation.d.ts.map +1 -0
  96. package/dist/server/src/types.d.ts +28 -0
  97. package/dist/server/src/types.d.ts.map +1 -0
  98. package/dist/server/src/utils.d.ts +12 -0
  99. package/dist/server/src/utils.d.ts.map +1 -0
  100. package/package.json +33 -16
  101. package/strapi-server.js +1 -1
  102. package/.eslintignore +0 -1
  103. package/.eslintrc +0 -17
  104. package/admin/src/constants.js +0 -17
  105. package/admin/src/hooks/useDocumentation.js +0 -81
  106. package/admin/src/index.js +0 -62
  107. package/admin/src/pages/PluginPage/index.jsx +0 -212
  108. package/admin/src/pages/PluginPage/tests/index.test.jsx +0 -160
  109. package/admin/src/pages/SettingsPage/index.jsx +0 -202
  110. package/admin/src/pages/SettingsPage/tests/index.test.jsx +0 -72
  111. package/admin/src/pluginId.js +0 -5
  112. package/admin/src/translations/ar.json +0 -20
  113. package/admin/src/translations/cs.json +0 -21
  114. package/admin/src/translations/de.json +0 -26
  115. package/admin/src/translations/dk.json +0 -39
  116. package/admin/src/translations/en.json +0 -39
  117. package/admin/src/translations/es.json +0 -39
  118. package/admin/src/translations/fr.json +0 -26
  119. package/admin/src/translations/id.json +0 -24
  120. package/admin/src/translations/it.json +0 -26
  121. package/admin/src/translations/ko.json +0 -39
  122. package/admin/src/translations/ms.json +0 -23
  123. package/admin/src/translations/nl.json +0 -21
  124. package/admin/src/translations/pl.json +0 -39
  125. package/admin/src/translations/pt-BR.json +0 -21
  126. package/admin/src/translations/pt.json +0 -21
  127. package/admin/src/translations/ru.json +0 -39
  128. package/admin/src/translations/sk.json +0 -24
  129. package/admin/src/translations/sv.json +0 -39
  130. package/admin/src/translations/th.json +0 -24
  131. package/admin/src/translations/tr.json +0 -39
  132. package/admin/src/translations/uk.json +0 -23
  133. package/admin/src/translations/vi.json +0 -24
  134. package/admin/src/translations/zh-Hans.json +0 -28
  135. package/admin/src/translations/zh.json +0 -39
  136. package/admin/src/utils/getTrad.js +0 -5
  137. package/admin/src/utils/index.js +0 -2
  138. package/admin/src/utils/prefixPluginTranslations.js +0 -13
  139. package/dist/_chunks/index-7xstUX8_.mjs.map +0 -1
  140. package/dist/_chunks/index-D1KkfApT.js.map +0 -1
  141. package/dist/_chunks/index-NbPCucJl.js.map +0 -1
  142. package/dist/_chunks/index-NvJ4m2q5.mjs.map +0 -1
  143. package/dist/_chunks/index-VpLAJXMs.mjs.map +0 -1
  144. package/dist/_chunks/index-r7HsQTou.js.map +0 -1
  145. package/dist/_chunks/useDocumentation-6Ks-_Ms6.mjs +0 -68
  146. package/dist/_chunks/useDocumentation-6Ks-_Ms6.mjs.map +0 -1
  147. package/dist/_chunks/useDocumentation-S0e4mU-U.js +0 -67
  148. package/dist/_chunks/useDocumentation-S0e4mU-U.js.map +0 -1
  149. package/jest.config.front.js +0 -7
  150. package/jest.config.js +0 -6
  151. package/packup.config.ts +0 -22
  152. package/server/bootstrap.js +0 -54
  153. package/server/config/default-plugin-config.js +0 -35
  154. package/server/config/index.js +0 -7
  155. package/server/controllers/documentation.js +0 -241
  156. package/server/controllers/index.js +0 -7
  157. package/server/index.js +0 -17
  158. package/server/middlewares/documentation.js +0 -25
  159. package/server/middlewares/index.js +0 -7
  160. package/server/middlewares/restrict-access.js +0 -24
  161. package/server/register.js +0 -11
  162. package/server/routes/index.js +0 -84
  163. package/server/services/__mocks__/mock-content-types.js +0 -264
  164. package/server/services/__mocks__/mock-strapi-data.js +0 -183
  165. package/server/services/__tests__/build-component-schema.test.js +0 -761
  166. package/server/services/__tests__/documentation.test.js +0 -481
  167. package/server/services/__tests__/override.test.js +0 -85
  168. package/server/services/documentation.js +0 -246
  169. package/server/services/helpers/build-api-endpoint-path.js +0 -186
  170. package/server/services/helpers/build-component-schema.js +0 -254
  171. package/server/services/helpers/index.js +0 -9
  172. package/server/services/helpers/utils/clean-schema-attributes.js +0 -246
  173. package/server/services/helpers/utils/get-api-responses.js +0 -105
  174. package/server/services/helpers/utils/get-schema-data.js +0 -32
  175. package/server/services/helpers/utils/loop-content-type-names.js +0 -55
  176. package/server/services/helpers/utils/pascal-case.js +0 -9
  177. package/server/services/helpers/utils/query-params.js +0 -105
  178. package/server/services/helpers/utils/routes.js +0 -10
  179. package/server/services/index.js +0 -9
  180. package/server/services/override.js +0 -52
  181. package/server/services/utils/default-openapi-components.js +0 -40
  182. package/server/services/utils/get-plugins-that-need-documentation.js +0 -24
  183. package/tests/server.js +0 -37
  184. package/tests/setup.js +0 -15
@@ -1,246 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs-extra');
5
- const { produce } = require('immer');
6
- const { builApiEndpointPath, buildComponentSchema } = require('./helpers');
7
-
8
- const defaultOpenApiComponents = require('./utils/default-openapi-components');
9
- const { getPluginsThatNeedDocumentation } = require('./utils/get-plugins-that-need-documentation');
10
-
11
- module.exports = ({ strapi }) => {
12
- const config = strapi.config.get('plugin::documentation');
13
- const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(config);
14
- const overrideService = strapi.plugin('documentation').service('override');
15
-
16
- return {
17
- /**
18
- *
19
- * @deprecated
20
- * registerDoc is deprecated it will be removed in the next major release,
21
- * use strapi.plugin('documentation').service('override').registerOverride() instead
22
- * @param {object} doc - The openapi specifcation to override
23
- * @param {object} options - The options to override the documentation
24
- * @param {string} options.pluginOrigin - The name of the plugin that is overriding the documentation
25
- * @param {string[]} options.excludeFromGeneration - The name of the plugin that is overriding the documentation
26
- */
27
- registerDoc(doc, options) {
28
- strapi.log.warn(
29
- "@strapi/plugin-documentation has deprecated registerDoc, use strapi.plugin('documentation').service('override').registerOverride() instead"
30
- );
31
- overrideService.registerOverride(doc, options);
32
- },
33
-
34
- getDocumentationVersion() {
35
- return config.info.version;
36
- },
37
-
38
- getFullDocumentationPath() {
39
- return path.join(strapi.dirs.app.extensions, 'documentation', 'documentation');
40
- },
41
-
42
- /**
43
- *
44
- * @deprecated
45
- * This method will be removed in the next major release
46
- */
47
- getCustomDocumentationPath() {
48
- return path.join(strapi.dirs.app.extensions, 'documentation', 'config', 'settings.json');
49
- },
50
-
51
- getDocumentationVersions() {
52
- return fs
53
- .readdirSync(this.getFullDocumentationPath())
54
- .map((version) => {
55
- try {
56
- const doc = JSON.parse(
57
- fs.readFileSync(
58
- path.resolve(this.getFullDocumentationPath(), version, 'full_documentation.json')
59
- )
60
- );
61
-
62
- const generatedDate = doc.info['x-generation-date'];
63
-
64
- return { version, generatedDate, url: '' };
65
- } catch (err) {
66
- return null;
67
- }
68
- })
69
- .filter((x) => x);
70
- },
71
-
72
- /**
73
- * Returns settings stored in core-store
74
- */
75
- async getDocumentationAccess() {
76
- const { restrictedAccess } = await strapi
77
- .store({
78
- environment: '',
79
- type: 'plugin',
80
- name: 'documentation',
81
- key: 'config',
82
- })
83
- .get();
84
-
85
- return { restrictedAccess };
86
- },
87
-
88
- /**
89
- * @description - Gets the path for an api or plugin
90
- *
91
- * @param {object} api
92
- * @property {string} api.name - Name of the api
93
- * @property {string} api.getter - api | plugin
94
- *
95
- * @returns path to the api | plugin
96
- */
97
- getApiDocumentationPath(api) {
98
- if (api.getter === 'plugin') {
99
- return path.join(strapi.dirs.app.extensions, api.name, 'documentation');
100
- }
101
-
102
- return path.join(strapi.dirs.app.api, api.name, 'documentation');
103
- },
104
-
105
- async deleteDocumentation(version) {
106
- const apis = this.getPluginAndApiInfo();
107
- for (const api of apis) {
108
- await fs.remove(path.join(this.getApiDocumentationPath(api), version));
109
- }
110
-
111
- await fs.remove(path.join(this.getFullDocumentationPath(), version));
112
- },
113
-
114
- getPluginAndApiInfo() {
115
- const pluginsToDocument = pluginsThatNeedDocumentation.map((plugin) => {
116
- return {
117
- name: plugin,
118
- getter: 'plugin',
119
- ctNames: Object.keys(strapi.plugin(plugin).contentTypes),
120
- };
121
- });
122
-
123
- const apisToDocument = Object.keys(strapi.api).map((api) => {
124
- return {
125
- name: api,
126
- getter: 'api',
127
- ctNames: Object.keys(strapi.api[api].contentTypes),
128
- };
129
- });
130
-
131
- return [...apisToDocument, ...pluginsToDocument];
132
- },
133
-
134
- /**
135
- * @description - Creates the Swagger json files
136
- */
137
- async generateFullDoc(version = this.getDocumentationVersion()) {
138
- const apis = this.getPluginAndApiInfo();
139
- const apisThatNeedGeneratedDocumentation = apis.filter(
140
- ({ name }) => !overrideService.excludedFromGeneration.includes(name)
141
- );
142
-
143
- // Initialize the generated documentation with defaults
144
- let generatedDocumentation = produce(
145
- {
146
- ...config,
147
- components: defaultOpenApiComponents,
148
- },
149
- (draft) => {
150
- if (draft.servers.length === 0) {
151
- // When no servers found set the defaults
152
- const serverUrl = strapi.config.get('server.absoluteUrl');
153
- const apiPath = strapi.config.get('api.rest.prefix');
154
- draft.servers = [
155
- {
156
- url: `${serverUrl}${apiPath}`,
157
- description: 'Development server',
158
- },
159
- ];
160
- }
161
- // Set the generated date
162
- draft.info['x-generation-date'] = new Date().toISOString();
163
- // Set the plugins that need documentation
164
- draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;
165
- // Delete the mutateDocumentation key from the config so it doesn't end up in the spec
166
- delete draft['x-strapi-config'].mutateDocumentation;
167
- }
168
- );
169
- // Generate the documentation for each api and update the generatedDocumentation
170
- for (const api of apisThatNeedGeneratedDocumentation) {
171
- const apiName = api.name;
172
-
173
- const newApiPath = builApiEndpointPath(api);
174
- const generatedSchemas = buildComponentSchema(api);
175
-
176
- // TODO: To be confirmed, do we still need to write these files...?
177
- const apiDirPath = path.join(this.getApiDocumentationPath(api), version);
178
- const apiDocPath = path.join(apiDirPath, `${apiName}.json`);
179
- await fs.ensureFile(apiDocPath);
180
- await fs.writeJson(apiDocPath, newApiPath, { spaces: 2 });
181
-
182
- generatedDocumentation = produce(generatedDocumentation, (draft) => {
183
- if (generatedSchemas) {
184
- draft.components.schemas = { ...draft.components.schemas, ...generatedSchemas };
185
- }
186
-
187
- if (newApiPath) {
188
- draft.paths = { ...draft.paths, ...newApiPath };
189
- }
190
- });
191
- }
192
-
193
- // When overrides are present update the generatedDocumentation
194
- if (overrideService.registeredOverrides.length > 0) {
195
- generatedDocumentation = produce(generatedDocumentation, (draft) => {
196
- overrideService.registeredOverrides.forEach((override) => {
197
- // Only run the overrrides when no override version is provided,
198
- // or when the generated documentation version matches the override version
199
- if (!override?.info?.version || override.info.version === version) {
200
- if (override.tags) {
201
- // Merge override tags with the generated tags
202
- draft.tags = draft.tags || [];
203
- draft.tags.push(...override.tags);
204
- }
205
-
206
- if (override.paths) {
207
- // Merge override paths with the generated paths
208
- // The override will add a new path or replace the value of an existing path
209
- draft.paths = { ...draft.paths, ...override.paths };
210
- }
211
-
212
- if (override.components) {
213
- Object.entries(override.components).forEach(([overrideKey, overrideValue]) => {
214
- draft.components[overrideKey] = draft.components[overrideKey] || {};
215
- // Merge override components with the generated components,
216
- // The override will add a new component or replace the value of an existing component
217
- draft.components[overrideKey] = {
218
- ...draft.components[overrideKey],
219
- ...overrideValue,
220
- };
221
- });
222
- }
223
- }
224
- });
225
- });
226
- }
227
-
228
- // Escape hatch, allow the user to provide a mutateDocumentation function that can alter any part of
229
- // the generated documentation before it is written to the file system
230
- const userMutatesDocumentation = config['x-strapi-config'].mutateDocumentation;
231
- const finalDocumentation = userMutatesDocumentation
232
- ? produce(generatedDocumentation, userMutatesDocumentation)
233
- : generatedDocumentation;
234
-
235
- // Get the file path for the final documentation
236
- const fullDocJsonPath = path.join(
237
- this.getFullDocumentationPath(),
238
- version,
239
- 'full_documentation.json'
240
- );
241
- // Write the documentation to the file system
242
- await fs.ensureFile(fullDocJsonPath);
243
- await fs.writeJson(fullDocJsonPath, finalDocumentation, { spaces: 2 });
244
- },
245
- };
246
- };
@@ -1,186 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
- const pathToRegexp = require('path-to-regexp');
5
-
6
- const pascalCase = require('./utils/pascal-case');
7
- const queryParams = require('./utils/query-params');
8
- const loopContentTypeNames = require('./utils/loop-content-type-names');
9
- const getApiResponses = require('./utils/get-api-responses');
10
- const { hasFindMethod, isLocalizedPath } = require('./utils/routes');
11
-
12
- /**
13
- * @description Parses a route with ':variable'
14
- *
15
- * @param {string} routePath - The route's path property
16
- * @returns {string}
17
- */
18
- const parsePathWithVariables = (routePath) => {
19
- return pathToRegexp
20
- .parse(routePath)
21
- .map((token) => {
22
- if (_.isObject(token)) {
23
- return `${token.prefix}{${token.name}}`;
24
- }
25
-
26
- return token;
27
- })
28
- .join('');
29
- };
30
-
31
- /**
32
- * @description Builds the required object for a path parameter
33
- *
34
- * @param {string} routePath - The route's path property
35
- *
36
- * @returns {object } Swagger path params object
37
- */
38
- const getPathParams = (routePath) => {
39
- return pathToRegexp
40
- .parse(routePath)
41
- .filter((token) => _.isObject(token))
42
- .map((param) => {
43
- return {
44
- name: param.name,
45
- in: 'path',
46
- description: '',
47
- deprecated: false,
48
- required: true,
49
- schema: { type: 'number' },
50
- };
51
- });
52
- };
53
-
54
- /**
55
- *
56
- * @param {string} prefix - The prefix found on the routes object
57
- * @param {string} route - The current route
58
- * @property {string} route.path - The current route's path
59
- * @property {object} route.config - The current route's config object
60
- *
61
- * @returns {string}
62
- */
63
- const getPathWithPrefix = (prefix, route) => {
64
- // When the prefix is set on the routes and
65
- // the current route is not trying to remove it
66
- if (prefix && !_.has(route.config, 'prefix')) {
67
- // Add the prefix to the path
68
- return prefix.concat(route.path);
69
- }
70
-
71
- // Otherwise just return path
72
- return route.path;
73
- };
74
- /**
75
- * @description Gets all paths based on routes
76
- *
77
- * @param {object} apiInfo
78
- * @property {object} apiInfo.routeInfo - The api routes object
79
- * @property {string} apiInfo.uniqueName - Content type name | Api name + Content type name
80
- * @property {object} apiInfo.contentTypeInfo - The info object found on content type schemas
81
- *
82
- * @returns {object}
83
- */
84
- const getPaths = ({ routeInfo, uniqueName, contentTypeInfo, kind }) => {
85
- // Get the routes for the current content type
86
- const contentTypeRoutes = routeInfo.routes.filter((route) => {
87
- return (
88
- route.path.includes(contentTypeInfo.pluralName) ||
89
- route.path.includes(contentTypeInfo.singularName)
90
- );
91
- });
92
-
93
- const paths = contentTypeRoutes.reduce((acc, route) => {
94
- // TODO: Find a more reliable way to determine list of entities vs a single entity
95
- const isListOfEntities = hasFindMethod(route.handler);
96
- const isLocalizationPath = isLocalizedPath(route.path);
97
- const methodVerb = route.method.toLowerCase();
98
- const hasPathParams = route.path.includes('/:');
99
- const pathWithPrefix = getPathWithPrefix(routeInfo.prefix, route);
100
- const routePath = hasPathParams ? parsePathWithVariables(pathWithPrefix) : pathWithPrefix;
101
-
102
- const { responses } = getApiResponses({
103
- uniqueName,
104
- route,
105
- isListOfEntities: kind !== 'singleType' && isListOfEntities,
106
- isLocalizationPath,
107
- });
108
-
109
- const swaggerConfig = {
110
- responses,
111
- tags: [_.upperFirst(uniqueName)],
112
- parameters: [],
113
- operationId: `${methodVerb}${routePath}`,
114
- };
115
-
116
- if (isListOfEntities) {
117
- swaggerConfig.parameters.push(...queryParams);
118
- }
119
-
120
- if (hasPathParams) {
121
- const pathParams = getPathParams(route.path);
122
- swaggerConfig.parameters.push(...pathParams);
123
- }
124
-
125
- if (['post', 'put'].includes(methodVerb)) {
126
- const refName = isLocalizationPath ? 'LocalizationRequest' : 'Request';
127
- const requestBody = {
128
- required: true,
129
- content: {
130
- 'application/json': {
131
- schema: {
132
- $ref: `#/components/schemas/${pascalCase(uniqueName)}${refName}`,
133
- },
134
- },
135
- },
136
- };
137
-
138
- swaggerConfig.requestBody = requestBody;
139
- }
140
-
141
- _.set(acc, `${routePath}.${methodVerb}`, swaggerConfig);
142
-
143
- return acc;
144
- }, {});
145
-
146
- return paths;
147
- };
148
-
149
- /**
150
- * @decription Gets all open api paths object for a given content type
151
- *
152
- * @param {object} apiInfo
153
- *
154
- * @returns {object} Open API paths
155
- */
156
- const getAllPathsForContentType = (apiInfo) => {
157
- let paths = {};
158
-
159
- const pathsObject = getPaths(apiInfo);
160
-
161
- paths = {
162
- ...paths,
163
- ...pathsObject,
164
- };
165
-
166
- return paths;
167
- };
168
-
169
- /**
170
- * @description - Builds the Swagger paths object for each api
171
- *
172
- * @param {object} api - Information about the current api
173
- * @property {string} api.name - The name of the api
174
- * @property {string} api.getter - The getter for the api (api | plugin)
175
- * @property {array} api.ctNames - The name of all contentTypes found on the api
176
- *
177
- * @returns {object}
178
- */
179
- const buildApiEndpointPath = (api) => {
180
- // A reusable loop for building paths and component schemas
181
- // Uses the api param to build a new set of params for each content type
182
- // Passes these new params to the function provided
183
- return loopContentTypeNames(api, getAllPathsForContentType);
184
- };
185
-
186
- module.exports = buildApiEndpointPath;
@@ -1,254 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
-
5
- const cleanSchemaAttributes = require('./utils/clean-schema-attributes');
6
- const loopContentTypeNames = require('./utils/loop-content-type-names');
7
- const pascalCase = require('./utils/pascal-case');
8
- const { hasFindMethod, isLocalizedPath } = require('./utils/routes');
9
-
10
- const getRequiredAttributes = (allAttributes) => {
11
- return Object.entries(allAttributes).reduce((acc, attribute) => {
12
- const [attributeKey, attributeValue] = attribute;
13
-
14
- if (attributeValue.required) {
15
- acc.push(attributeKey);
16
- }
17
-
18
- return acc;
19
- }, []);
20
- };
21
-
22
- /**
23
- * @decription Get all open api schema objects for a given content type
24
- *
25
- * @param {object} apiInfo
26
- * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name
27
- * @property {object} apiInfo.attributes - Attributes on content type
28
- * @property {object} apiInfo.routeInfo - The routes for the api
29
- *
30
- * @returns {object} Open API schemas
31
- */
32
- const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => {
33
- // Store response and request schemas in an object
34
- let schemas = {};
35
- let strapiComponentSchemas = {};
36
- // adds a ComponentSchema to the Schemas so it can be used as Ref
37
- const didAddStrapiComponentsToSchemas = (schemaName, schema) => {
38
- if (!Object.keys(schema) || !Object.keys(schema.properties)) return false;
39
-
40
- // Add the Strapi components to the schema
41
- strapiComponentSchemas = {
42
- ...strapiComponentSchemas,
43
- [schemaName]: schema,
44
- };
45
-
46
- return true;
47
- };
48
- // Get all the route methods
49
- const routeMethods = routeInfo.routes.map((route) => route.method);
50
- // Check for localized paths
51
- const hasLocalizationPath = routeInfo.routes.filter((route) =>
52
- isLocalizedPath(route.path)
53
- ).length;
54
-
55
- const attributesToOmit = [
56
- 'createdAt',
57
- 'updatedAt',
58
- 'publishedAt',
59
- 'publishedBy',
60
- 'updatedBy',
61
- 'createdBy',
62
- 'localizations',
63
- ];
64
- const attributesForRequest = _.omit(attributes, attributesToOmit);
65
- // Get a list of required attribute names
66
- const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);
67
- // Build the request schemas when the route has POST or PUT methods
68
- if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {
69
- // Build localization requests schemas
70
- if (hasLocalizationPath) {
71
- schemas = {
72
- ...schemas,
73
- [`${pascalCase(uniqueName)}LocalizationRequest`]: {
74
- required: [...requiredRequestAttributes, 'locale'],
75
- type: 'object',
76
- properties: cleanSchemaAttributes(attributesForRequest, {
77
- isRequest: true,
78
- didAddStrapiComponentsToSchemas,
79
- }),
80
- },
81
- };
82
- }
83
-
84
- // Build the request schema
85
- schemas = {
86
- ...schemas,
87
- [`${pascalCase(uniqueName)}Request`]: {
88
- type: 'object',
89
- required: ['data'],
90
- properties: {
91
- data: {
92
- ...(requiredRequestAttributes.length && { required: requiredRequestAttributes }),
93
- type: 'object',
94
- properties: cleanSchemaAttributes(attributesForRequest, {
95
- isRequest: true,
96
- didAddStrapiComponentsToSchemas,
97
- }),
98
- },
99
- },
100
- },
101
- };
102
- }
103
-
104
- // Build the localization response schema
105
- if (hasLocalizationPath) {
106
- schemas = {
107
- ...schemas,
108
- [`${pascalCase(uniqueName)}ResponseDataObjectLocalized`]: {
109
- type: 'object',
110
- properties: {
111
- id: { type: 'number' },
112
- attributes: {
113
- $ref: `#/components/schemas/${pascalCase(uniqueName)}`,
114
- },
115
- },
116
- },
117
- [`${pascalCase(uniqueName)}LocalizationResponse`]: {
118
- type: 'object',
119
- properties: {
120
- data: {
121
- $ref: `#/components/schemas/${pascalCase(uniqueName)}ResponseDataObjectLocalized`,
122
- },
123
- meta: { type: 'object' },
124
- },
125
- },
126
- };
127
- }
128
-
129
- // Check for routes that need to return a list
130
- const hasListOfEntities = routeInfo.routes.filter((route) => hasFindMethod(route.handler)).length;
131
- if (hasListOfEntities) {
132
- // Buld the localized list response schema
133
- if (hasLocalizationPath) {
134
- schemas = {
135
- ...schemas,
136
- [`${pascalCase(uniqueName)}ListResponseDataItemLocalized`]: {
137
- type: 'object',
138
- properties: {
139
- id: { type: 'number' },
140
- attributes: {
141
- $ref: `#/components/schemas/${pascalCase(uniqueName)}`,
142
- },
143
- },
144
- },
145
- [`${pascalCase(uniqueName)}LocalizationListResponse`]: {
146
- type: 'object',
147
- properties: {
148
- data: {
149
- type: 'array',
150
- items: {
151
- $ref: `#/components/schemas/${pascalCase(uniqueName)}ListResponseDataItemLocalized`,
152
- },
153
- },
154
- meta: {
155
- type: 'object',
156
- properties: {
157
- pagination: {
158
- type: 'object',
159
- properties: {
160
- page: { type: 'integer' },
161
- pageSize: { type: 'integer', minimum: 25 },
162
- pageCount: { type: 'integer', maximum: 1 },
163
- total: { type: 'integer' },
164
- },
165
- },
166
- },
167
- },
168
- },
169
- },
170
- };
171
- }
172
- // Build the list response schema
173
- schemas = {
174
- ...schemas,
175
- [`${pascalCase(uniqueName)}ListResponseDataItem`]: {
176
- type: 'object',
177
- properties: {
178
- id: { type: 'number' },
179
- attributes: {
180
- $ref: `#/components/schemas/${pascalCase(uniqueName)}`,
181
- },
182
- },
183
- },
184
- [`${pascalCase(uniqueName)}ListResponse`]: {
185
- type: 'object',
186
- properties: {
187
- data: {
188
- type: 'array',
189
- items: {
190
- $ref: `#/components/schemas/${pascalCase(uniqueName)}ListResponseDataItem`,
191
- },
192
- },
193
- meta: {
194
- type: 'object',
195
- properties: {
196
- pagination: {
197
- type: 'object',
198
- properties: {
199
- page: { type: 'integer' },
200
- pageSize: { type: 'integer', minimum: 25 },
201
- pageCount: { type: 'integer', maximum: 1 },
202
- total: { type: 'integer' },
203
- },
204
- },
205
- },
206
- },
207
- },
208
- },
209
- };
210
- }
211
-
212
- const requiredAttributes = getRequiredAttributes(attributes);
213
- // Build the response schema
214
- schemas = {
215
- ...schemas,
216
- [`${pascalCase(uniqueName)}`]: {
217
- type: 'object',
218
- ...(requiredAttributes.length && { required: requiredAttributes }),
219
- properties: cleanSchemaAttributes(attributes, {
220
- didAddStrapiComponentsToSchemas,
221
- componentSchemaRefName: `#/components/schemas/${pascalCase(uniqueName)}`,
222
- }),
223
- },
224
- [`${pascalCase(uniqueName)}ResponseDataObject`]: {
225
- type: 'object',
226
- properties: {
227
- id: { type: 'number' },
228
- attributes: {
229
- $ref: `#/components/schemas/${pascalCase(uniqueName)}`,
230
- },
231
- },
232
- },
233
- [`${pascalCase(uniqueName)}Response`]: {
234
- type: 'object',
235
- properties: {
236
- data: {
237
- $ref: `#/components/schemas/${pascalCase(uniqueName)}ResponseDataObject`,
238
- },
239
- meta: { type: 'object' },
240
- },
241
- },
242
- };
243
-
244
- return { ...schemas, ...strapiComponentSchemas };
245
- };
246
-
247
- const buildComponentSchema = (api) => {
248
- // A reusable loop for building paths and component schemas
249
- // Uses the api param to build a new set of params for each content type
250
- // Passes these new params to the function provided
251
- return loopContentTypeNames(api, getAllSchemasForContentType);
252
- };
253
-
254
- module.exports = buildComponentSchema;
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- const builApiEndpointPath = require('./build-api-endpoint-path');
4
- const buildComponentSchema = require('./build-component-schema');
5
-
6
- module.exports = {
7
- builApiEndpointPath,
8
- buildComponentSchema,
9
- };