@strapi/plugin-documentation 5.12.1 → 5.12.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.
- package/dist/admin/{chunks/Settings-Cpj-uI9B.js → components/SettingsForm.js} +7 -52
- package/dist/admin/components/SettingsForm.js.map +1 -0
- package/dist/admin/{chunks/Settings-DyLMOJEx.mjs → components/SettingsForm.mjs} +7 -52
- package/dist/admin/components/SettingsForm.mjs.map +1 -0
- package/dist/admin/constants.js +47 -0
- package/dist/admin/constants.js.map +1 -0
- package/dist/admin/constants.mjs +45 -0
- package/dist/admin/constants.mjs.map +1 -0
- package/dist/admin/index.js +93 -3
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +94 -2
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/{chunks/App-DC2H8bJ5.js → pages/App.js} +8 -8
- package/dist/admin/pages/App.js.map +1 -0
- package/dist/admin/{chunks/App-D6yQIQar.mjs → pages/App.mjs} +4 -4
- package/dist/admin/pages/App.mjs.map +1 -0
- package/dist/admin/pages/Settings.js +54 -0
- package/dist/admin/pages/Settings.js.map +1 -0
- package/dist/admin/pages/Settings.mjs +52 -0
- package/dist/admin/pages/Settings.mjs.map +1 -0
- package/dist/admin/pluginId.js +6 -0
- package/dist/admin/pluginId.js.map +1 -0
- package/dist/admin/pluginId.mjs +4 -0
- package/dist/admin/pluginId.mjs.map +1 -0
- package/dist/admin/{chunks/getTrad-AvLNMP3V.js → services/api.js} +1 -5
- package/dist/admin/services/api.js.map +1 -0
- package/dist/admin/{chunks/getTrad-D9juLfq6.mjs → services/api.mjs} +2 -5
- package/dist/admin/services/api.mjs.map +1 -0
- package/dist/admin/{chunks/ar-Dix6VU4a.js → translations/ar.json.js} +2 -2
- package/dist/admin/translations/ar.json.js.map +1 -0
- package/dist/admin/{chunks/ar-Bu09tPI1.mjs → translations/ar.json.mjs} +1 -1
- package/dist/admin/translations/ar.json.mjs.map +1 -0
- package/dist/admin/{chunks/cs-C6k-mH5i.js → translations/cs.json.js} +2 -2
- package/dist/admin/translations/cs.json.js.map +1 -0
- package/dist/admin/{chunks/cs-tf-UeGst.mjs → translations/cs.json.mjs} +1 -1
- package/dist/admin/translations/cs.json.mjs.map +1 -0
- package/dist/admin/{chunks/de-DYskRe8j.js → translations/de.json.js} +2 -2
- package/dist/admin/translations/de.json.js.map +1 -0
- package/dist/admin/{chunks/de-CMhqnPQP.mjs → translations/de.json.mjs} +1 -1
- package/dist/admin/translations/de.json.mjs.map +1 -0
- package/dist/admin/{chunks/dk-BYJqzR_M.js → translations/dk.json.js} +2 -2
- package/dist/admin/translations/dk.json.js.map +1 -0
- package/dist/admin/{chunks/dk-BmQOOeIc.mjs → translations/dk.json.mjs} +1 -1
- package/dist/admin/translations/dk.json.mjs.map +1 -0
- package/dist/admin/{chunks/en-B90IBmYB.js → translations/en.json.js} +2 -2
- package/dist/admin/translations/en.json.js.map +1 -0
- package/dist/admin/{chunks/en-Cx8yPuig.mjs → translations/en.json.mjs} +1 -1
- package/dist/admin/translations/en.json.mjs.map +1 -0
- package/dist/admin/{chunks/es-5WsjlhIl.js → translations/es.json.js} +2 -2
- package/dist/admin/translations/es.json.js.map +1 -0
- package/dist/admin/{chunks/es-DAdgO3Ey.mjs → translations/es.json.mjs} +1 -1
- package/dist/admin/translations/es.json.mjs.map +1 -0
- package/dist/admin/{chunks/fr-C-vHEudQ.js → translations/fr.json.js} +2 -2
- package/dist/admin/translations/fr.json.js.map +1 -0
- package/dist/admin/{chunks/fr-B5fjFqKX.mjs → translations/fr.json.mjs} +1 -1
- package/dist/admin/translations/fr.json.mjs.map +1 -0
- package/dist/admin/{chunks/id-BKiCYOdS.js → translations/id.json.js} +2 -2
- package/dist/admin/translations/id.json.js.map +1 -0
- package/dist/admin/{chunks/id-CLApXj97.mjs → translations/id.json.mjs} +1 -1
- package/dist/admin/translations/id.json.mjs.map +1 -0
- package/dist/admin/{chunks/it-B7SnHLP2.js → translations/it.json.js} +2 -2
- package/dist/admin/translations/it.json.js.map +1 -0
- package/dist/admin/{chunks/it-C7GcWYBa.mjs → translations/it.json.mjs} +1 -1
- package/dist/admin/translations/it.json.mjs.map +1 -0
- package/dist/admin/{chunks/ko-CjOasZmz.js → translations/ko.json.js} +2 -2
- package/dist/admin/translations/ko.json.js.map +1 -0
- package/dist/admin/{chunks/ko-DZvks90a.mjs → translations/ko.json.mjs} +1 -1
- package/dist/admin/translations/ko.json.mjs.map +1 -0
- package/dist/admin/{chunks/ms-C2TEZHkD.js → translations/ms.json.js} +2 -2
- package/dist/admin/translations/ms.json.js.map +1 -0
- package/dist/admin/{chunks/ms-Df9gDB9M.mjs → translations/ms.json.mjs} +1 -1
- package/dist/admin/translations/ms.json.mjs.map +1 -0
- package/dist/admin/{chunks/nl-CLp2dhr9.js → translations/nl.json.js} +2 -2
- package/dist/admin/translations/nl.json.js.map +1 -0
- package/dist/admin/{chunks/nl-BlmTMaTL.mjs → translations/nl.json.mjs} +1 -1
- package/dist/admin/translations/nl.json.mjs.map +1 -0
- package/dist/admin/{chunks/pl-C8WRO2pt.js → translations/pl.json.js} +2 -2
- package/dist/admin/translations/pl.json.js.map +1 -0
- package/dist/admin/{chunks/pl-5iT3b9r4.mjs → translations/pl.json.mjs} +1 -1
- package/dist/admin/translations/pl.json.mjs.map +1 -0
- package/dist/admin/{chunks/pt-BR-Ds-dLXzD.js → translations/pt-BR.json.js} +2 -2
- package/dist/admin/translations/pt-BR.json.js.map +1 -0
- package/dist/admin/{chunks/pt-BR-De5jokla.mjs → translations/pt-BR.json.mjs} +1 -1
- package/dist/admin/translations/pt-BR.json.mjs.map +1 -0
- package/dist/admin/{chunks/pt-DL-rrjA1.js → translations/pt.json.js} +2 -2
- package/dist/admin/translations/pt.json.js.map +1 -0
- package/dist/admin/{chunks/pt-BK5YbXpM.mjs → translations/pt.json.mjs} +1 -1
- package/dist/admin/translations/pt.json.mjs.map +1 -0
- package/dist/admin/{chunks/ru-Cqv4k9my.js → translations/ru.json.js} +2 -2
- package/dist/admin/translations/ru.json.js.map +1 -0
- package/dist/admin/{chunks/ru-C_16WuLP.mjs → translations/ru.json.mjs} +1 -1
- package/dist/admin/translations/ru.json.mjs.map +1 -0
- package/dist/admin/{chunks/sk-D6l_EMOT.js → translations/sk.json.js} +2 -2
- package/dist/admin/translations/sk.json.js.map +1 -0
- package/dist/admin/{chunks/sk-B7RadPe4.mjs → translations/sk.json.mjs} +1 -1
- package/dist/admin/translations/sk.json.mjs.map +1 -0
- package/dist/admin/{chunks/sv-Xg5gbVO9.js → translations/sv.json.js} +2 -2
- package/dist/admin/translations/sv.json.js.map +1 -0
- package/dist/admin/{chunks/sv-DK5DOsrV.mjs → translations/sv.json.mjs} +1 -1
- package/dist/admin/translations/sv.json.mjs.map +1 -0
- package/dist/admin/{chunks/th-Pci1U3n6.js → translations/th.json.js} +2 -2
- package/dist/admin/translations/th.json.js.map +1 -0
- package/dist/admin/{chunks/th-DNiRgKQH.mjs → translations/th.json.mjs} +1 -1
- package/dist/admin/translations/th.json.mjs.map +1 -0
- package/dist/admin/{chunks/tr-CBlxk5Of.js → translations/tr.json.js} +2 -2
- package/dist/admin/translations/tr.json.js.map +1 -0
- package/dist/admin/{chunks/tr-CWX4cUiB.mjs → translations/tr.json.mjs} +1 -1
- package/dist/admin/translations/tr.json.mjs.map +1 -0
- package/dist/admin/{chunks/uk-BkF_x68T.js → translations/uk.json.js} +2 -2
- package/dist/admin/translations/uk.json.js.map +1 -0
- package/dist/admin/{chunks/uk-CWOtQQic.mjs → translations/uk.json.mjs} +1 -1
- package/dist/admin/translations/uk.json.mjs.map +1 -0
- package/dist/admin/{chunks/vi-CAG7iDHR.js → translations/vi.json.js} +2 -2
- package/dist/admin/translations/vi.json.js.map +1 -0
- package/dist/admin/{chunks/vi-geadDLtq.mjs → translations/vi.json.mjs} +1 -1
- package/dist/admin/translations/vi.json.mjs.map +1 -0
- package/dist/admin/{chunks/zh-Hans-CtXQdJhw.js → translations/zh-Hans.json.js} +2 -2
- package/dist/admin/translations/zh-Hans.json.js.map +1 -0
- package/dist/admin/{chunks/zh-Hans-fcRf-TLx.mjs → translations/zh-Hans.json.mjs} +1 -1
- package/dist/admin/translations/zh-Hans.json.mjs.map +1 -0
- package/dist/admin/{chunks/zh-rKHsKNA3.js → translations/zh.json.js} +2 -2
- package/dist/admin/translations/zh.json.js.map +1 -0
- package/dist/admin/{chunks/zh-E4LX--2j.mjs → translations/zh.json.mjs} +1 -1
- package/dist/admin/translations/zh.json.mjs.map +1 -0
- package/dist/admin/utils/baseQuery.js +8 -0
- package/dist/admin/utils/baseQuery.js.map +1 -0
- package/dist/admin/utils/baseQuery.mjs +6 -0
- package/dist/admin/utils/baseQuery.mjs.map +1 -0
- package/dist/admin/utils/getTrad.js +8 -0
- package/dist/admin/utils/getTrad.js.map +1 -0
- package/dist/admin/utils/getTrad.mjs +6 -0
- package/dist/admin/utils/getTrad.mjs.map +1 -0
- package/dist/admin/utils/prefixPluginTranslations.js +11 -0
- package/dist/admin/utils/prefixPluginTranslations.js.map +1 -0
- package/dist/admin/utils/prefixPluginTranslations.mjs +9 -0
- package/dist/admin/utils/prefixPluginTranslations.mjs.map +1 -0
- package/dist/server/bootstrap.js +57 -0
- package/dist/server/bootstrap.js.map +1 -0
- package/dist/server/bootstrap.mjs +55 -0
- package/dist/server/bootstrap.mjs.map +1 -0
- package/dist/server/config/default-plugin-config.js +88 -0
- package/dist/server/config/default-plugin-config.js.map +1 -0
- package/dist/server/config/default-plugin-config.mjs +86 -0
- package/dist/server/config/default-plugin-config.mjs.map +1 -0
- package/dist/server/config/index.js +10 -0
- package/dist/server/config/index.js.map +1 -0
- package/dist/server/config/index.mjs +8 -0
- package/dist/server/config/index.mjs.map +1 -0
- package/dist/server/controllers/documentation.js +185 -0
- package/dist/server/controllers/documentation.js.map +1 -0
- package/dist/server/controllers/documentation.mjs +181 -0
- package/dist/server/controllers/documentation.mjs.map +1 -0
- package/dist/server/controllers/index.js +10 -0
- package/dist/server/controllers/index.js.map +1 -0
- package/dist/server/controllers/index.mjs +8 -0
- package/dist/server/controllers/index.mjs.map +1 -0
- package/dist/server/index.js +12 -1586
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +6 -1561
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/middlewares/documentation.js +27 -0
- package/dist/server/middlewares/documentation.js.map +1 -0
- package/dist/server/middlewares/documentation.mjs +25 -0
- package/dist/server/middlewares/documentation.mjs.map +1 -0
- package/dist/server/middlewares/restrict-access.js +23 -0
- package/dist/server/middlewares/restrict-access.js.map +1 -0
- package/dist/server/middlewares/restrict-access.mjs +21 -0
- package/dist/server/middlewares/restrict-access.mjs.map +1 -0
- package/dist/server/{chunks/index--0fU1WeK.js → public/index.html.js} +2 -2
- package/dist/server/public/index.html.js.map +1 -0
- package/dist/server/{chunks/index-Dz3orHaf.mjs → public/index.html.mjs} +1 -1
- package/dist/server/public/index.html.mjs.map +1 -0
- package/dist/server/{chunks/login-CMPqkCFT.js → public/login.html.js} +2 -2
- package/dist/server/public/login.html.js.map +1 -0
- package/dist/server/{chunks/login-CYdORE5u.mjs → public/login.html.mjs} +1 -1
- package/dist/server/public/login.html.mjs.map +1 -0
- package/dist/server/register.js +12 -0
- package/dist/server/register.js.map +1 -0
- package/dist/server/register.mjs +10 -0
- package/dist/server/register.mjs.map +1 -0
- package/dist/server/routes/index.js +106 -0
- package/dist/server/routes/index.js.map +1 -0
- package/dist/server/routes/index.mjs +104 -0
- package/dist/server/routes/index.mjs.map +1 -0
- package/dist/server/services/documentation.js +182 -0
- package/dist/server/services/documentation.js.map +1 -0
- package/dist/server/services/documentation.mjs +180 -0
- package/dist/server/services/documentation.mjs.map +1 -0
- package/dist/server/services/helpers/build-api-endpoint-path.js +162 -0
- package/dist/server/services/helpers/build-api-endpoint-path.js.map +1 -0
- package/dist/server/services/helpers/build-api-endpoint-path.mjs +141 -0
- package/dist/server/services/helpers/build-api-endpoint-path.mjs.map +1 -0
- package/dist/server/services/helpers/build-component-schema.js +167 -0
- package/dist/server/services/helpers/build-component-schema.js.map +1 -0
- package/dist/server/services/helpers/build-component-schema.mjs +165 -0
- package/dist/server/services/helpers/build-component-schema.mjs.map +1 -0
- package/dist/server/services/helpers/utils/clean-schema-attributes.js +301 -0
- package/dist/server/services/helpers/utils/clean-schema-attributes.js.map +1 -0
- package/dist/server/services/helpers/utils/clean-schema-attributes.mjs +299 -0
- package/dist/server/services/helpers/utils/clean-schema-attributes.mjs.map +1 -0
- package/dist/server/services/helpers/utils/get-api-responses.js +88 -0
- package/dist/server/services/helpers/utils/get-api-responses.js.map +1 -0
- package/dist/server/services/helpers/utils/get-api-responses.mjs +86 -0
- package/dist/server/services/helpers/utils/get-api-responses.mjs.map +1 -0
- package/dist/server/services/helpers/utils/get-schema-data.js +43 -0
- package/dist/server/services/helpers/utils/get-schema-data.js.map +1 -0
- package/dist/server/services/helpers/utils/get-schema-data.mjs +41 -0
- package/dist/server/services/helpers/utils/get-schema-data.mjs.map +1 -0
- package/dist/server/services/helpers/utils/loop-content-type-names.js +40 -0
- package/dist/server/services/helpers/utils/loop-content-type-names.js.map +1 -0
- package/dist/server/services/helpers/utils/loop-content-type-names.mjs +38 -0
- package/dist/server/services/helpers/utils/loop-content-type-names.mjs.map +1 -0
- package/dist/server/services/helpers/utils/pascal-case.js +10 -0
- package/dist/server/services/helpers/utils/pascal-case.js.map +1 -0
- package/dist/server/services/helpers/utils/pascal-case.mjs +8 -0
- package/dist/server/services/helpers/utils/pascal-case.mjs.map +1 -0
- package/dist/server/services/helpers/utils/query-params.js +109 -0
- package/dist/server/services/helpers/utils/query-params.js.map +1 -0
- package/dist/server/services/helpers/utils/query-params.mjs +107 -0
- package/dist/server/services/helpers/utils/query-params.mjs.map +1 -0
- package/dist/server/services/helpers/utils/routes.js +11 -0
- package/dist/server/services/helpers/utils/routes.js.map +1 -0
- package/dist/server/services/helpers/utils/routes.mjs +9 -0
- package/dist/server/services/helpers/utils/routes.mjs.map +1 -0
- package/dist/server/services/index.js +13 -0
- package/dist/server/services/index.js.map +1 -0
- package/dist/server/services/index.mjs +11 -0
- package/dist/server/services/index.mjs.map +1 -0
- package/dist/server/services/override.js +45 -0
- package/dist/server/services/override.js.map +1 -0
- package/dist/server/services/override.mjs +43 -0
- package/dist/server/services/override.mjs.map +1 -0
- package/dist/server/services/utils/get-plugins-that-need-documentation.js +24 -0
- package/dist/server/services/utils/get-plugins-that-need-documentation.js.map +1 -0
- package/dist/server/services/utils/get-plugins-that-need-documentation.mjs +22 -0
- package/dist/server/services/utils/get-plugins-that-need-documentation.mjs.map +1 -0
- package/dist/server/utils.js +10 -0
- package/dist/server/utils.js.map +1 -0
- package/dist/server/utils.mjs +8 -0
- package/dist/server/utils.mjs.map +1 -0
- package/package.json +6 -6
- package/dist/admin/chunks/App-D6yQIQar.mjs.map +0 -1
- package/dist/admin/chunks/App-DC2H8bJ5.js.map +0 -1
- package/dist/admin/chunks/Settings-Cpj-uI9B.js.map +0 -1
- package/dist/admin/chunks/Settings-DyLMOJEx.mjs.map +0 -1
- package/dist/admin/chunks/ar-Bu09tPI1.mjs.map +0 -1
- package/dist/admin/chunks/ar-Dix6VU4a.js.map +0 -1
- package/dist/admin/chunks/cs-C6k-mH5i.js.map +0 -1
- package/dist/admin/chunks/cs-tf-UeGst.mjs.map +0 -1
- package/dist/admin/chunks/de-CMhqnPQP.mjs.map +0 -1
- package/dist/admin/chunks/de-DYskRe8j.js.map +0 -1
- package/dist/admin/chunks/dk-BYJqzR_M.js.map +0 -1
- package/dist/admin/chunks/dk-BmQOOeIc.mjs.map +0 -1
- package/dist/admin/chunks/en-B90IBmYB.js.map +0 -1
- package/dist/admin/chunks/en-Cx8yPuig.mjs.map +0 -1
- package/dist/admin/chunks/es-5WsjlhIl.js.map +0 -1
- package/dist/admin/chunks/es-DAdgO3Ey.mjs.map +0 -1
- package/dist/admin/chunks/fr-B5fjFqKX.mjs.map +0 -1
- package/dist/admin/chunks/fr-C-vHEudQ.js.map +0 -1
- package/dist/admin/chunks/getTrad-AvLNMP3V.js.map +0 -1
- package/dist/admin/chunks/getTrad-D9juLfq6.mjs.map +0 -1
- package/dist/admin/chunks/id-BKiCYOdS.js.map +0 -1
- package/dist/admin/chunks/id-CLApXj97.mjs.map +0 -1
- package/dist/admin/chunks/index-BHy3RKs2.mjs +0 -144
- package/dist/admin/chunks/index-BHy3RKs2.mjs.map +0 -1
- package/dist/admin/chunks/index-BSW-EfNW.js +0 -148
- package/dist/admin/chunks/index-BSW-EfNW.js.map +0 -1
- package/dist/admin/chunks/it-B7SnHLP2.js.map +0 -1
- package/dist/admin/chunks/it-C7GcWYBa.mjs.map +0 -1
- package/dist/admin/chunks/ko-CjOasZmz.js.map +0 -1
- package/dist/admin/chunks/ko-DZvks90a.mjs.map +0 -1
- package/dist/admin/chunks/ms-C2TEZHkD.js.map +0 -1
- package/dist/admin/chunks/ms-Df9gDB9M.mjs.map +0 -1
- package/dist/admin/chunks/nl-BlmTMaTL.mjs.map +0 -1
- package/dist/admin/chunks/nl-CLp2dhr9.js.map +0 -1
- package/dist/admin/chunks/pl-5iT3b9r4.mjs.map +0 -1
- package/dist/admin/chunks/pl-C8WRO2pt.js.map +0 -1
- package/dist/admin/chunks/pt-BK5YbXpM.mjs.map +0 -1
- package/dist/admin/chunks/pt-BR-De5jokla.mjs.map +0 -1
- package/dist/admin/chunks/pt-BR-Ds-dLXzD.js.map +0 -1
- package/dist/admin/chunks/pt-DL-rrjA1.js.map +0 -1
- package/dist/admin/chunks/ru-C_16WuLP.mjs.map +0 -1
- package/dist/admin/chunks/ru-Cqv4k9my.js.map +0 -1
- package/dist/admin/chunks/sk-B7RadPe4.mjs.map +0 -1
- package/dist/admin/chunks/sk-D6l_EMOT.js.map +0 -1
- package/dist/admin/chunks/sv-DK5DOsrV.mjs.map +0 -1
- package/dist/admin/chunks/sv-Xg5gbVO9.js.map +0 -1
- package/dist/admin/chunks/th-DNiRgKQH.mjs.map +0 -1
- package/dist/admin/chunks/th-Pci1U3n6.js.map +0 -1
- package/dist/admin/chunks/tr-CBlxk5Of.js.map +0 -1
- package/dist/admin/chunks/tr-CWX4cUiB.mjs.map +0 -1
- package/dist/admin/chunks/uk-BkF_x68T.js.map +0 -1
- package/dist/admin/chunks/uk-CWOtQQic.mjs.map +0 -1
- package/dist/admin/chunks/vi-CAG7iDHR.js.map +0 -1
- package/dist/admin/chunks/vi-geadDLtq.mjs.map +0 -1
- package/dist/admin/chunks/zh-E4LX--2j.mjs.map +0 -1
- package/dist/admin/chunks/zh-Hans-CtXQdJhw.js.map +0 -1
- package/dist/admin/chunks/zh-Hans-fcRf-TLx.mjs.map +0 -1
- package/dist/admin/chunks/zh-rKHsKNA3.js.map +0 -1
- package/dist/server/chunks/index--0fU1WeK.js.map +0 -1
- package/dist/server/chunks/index-Dz3orHaf.mjs.map +0 -1
- package/dist/server/chunks/login-CMPqkCFT.js.map +0 -1
- package/dist/server/chunks/login-CYdORE5u.mjs.map +0 -1
package/dist/server/index.mjs
CHANGED
|
@@ -1,1564 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import * as pathToRegexp from 'path-to-regexp';
|
|
8
|
-
import bcrypt from 'bcryptjs';
|
|
9
|
-
import { validateYupSchema, yup } from '@strapi/utils';
|
|
10
|
-
|
|
11
|
-
const getService = (name, { strapi } = {
|
|
12
|
-
strapi: global.strapi
|
|
13
|
-
})=>{
|
|
14
|
-
return strapi.plugin('documentation').service(name);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Add permissions
|
|
18
|
-
const RBAC_ACTIONS = [
|
|
19
|
-
{
|
|
20
|
-
section: 'plugins',
|
|
21
|
-
displayName: 'Access the Documentation',
|
|
22
|
-
uid: 'read',
|
|
23
|
-
pluginName: 'documentation'
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
section: 'plugins',
|
|
27
|
-
displayName: 'Update and delete',
|
|
28
|
-
uid: 'settings.update',
|
|
29
|
-
pluginName: 'documentation'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
section: 'plugins',
|
|
33
|
-
displayName: 'Regenerate',
|
|
34
|
-
uid: 'settings.regenerate',
|
|
35
|
-
pluginName: 'documentation'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
section: 'settings',
|
|
39
|
-
displayName: 'Access the documentation settings page',
|
|
40
|
-
uid: 'settings.read',
|
|
41
|
-
pluginName: 'documentation',
|
|
42
|
-
category: 'documentation'
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
async function bootstrap({ strapi }) {
|
|
46
|
-
await strapi.service('admin::permission').actionProvider.registerMany(RBAC_ACTIONS);
|
|
47
|
-
const pluginStore = strapi.store({
|
|
48
|
-
environment: '',
|
|
49
|
-
type: 'plugin',
|
|
50
|
-
name: 'documentation'
|
|
51
|
-
});
|
|
52
|
-
const config = await pluginStore.get({
|
|
53
|
-
key: 'config'
|
|
54
|
-
});
|
|
55
|
-
if (!config) {
|
|
56
|
-
pluginStore.set({
|
|
57
|
-
key: 'config',
|
|
58
|
-
value: {
|
|
59
|
-
restrictedAccess: false
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
64
|
-
await getService('documentation').generateFullDoc();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const addDocumentMiddlewares = async ({ strapi })=>{
|
|
69
|
-
strapi.server.routes([
|
|
70
|
-
{
|
|
71
|
-
method: 'GET',
|
|
72
|
-
path: '/plugins/documentation/(.*)',
|
|
73
|
-
async handler (ctx, next) {
|
|
74
|
-
ctx.url = path.basename(ctx.url);
|
|
75
|
-
return koaStatic(swaggerUi.getAbsoluteFSPath(), {
|
|
76
|
-
maxage: 86400000,
|
|
77
|
-
defer: true
|
|
78
|
-
})(ctx, next);
|
|
79
|
-
},
|
|
80
|
-
config: {
|
|
81
|
-
auth: false
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
]);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
async function register({ strapi }) {
|
|
88
|
-
await addDocumentMiddlewares({
|
|
89
|
-
strapi
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const pascalCase = (string)=>{
|
|
94
|
-
return _.upperFirst(_.camelCase(string));
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const params = [
|
|
98
|
-
{
|
|
99
|
-
name: 'sort',
|
|
100
|
-
in: 'query',
|
|
101
|
-
description: 'Sort by attributes ascending (asc) or descending (desc)',
|
|
102
|
-
deprecated: false,
|
|
103
|
-
required: false,
|
|
104
|
-
schema: {
|
|
105
|
-
type: 'string'
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
name: 'pagination[withCount]',
|
|
110
|
-
in: 'query',
|
|
111
|
-
description: 'Return page/pageSize (default: true)',
|
|
112
|
-
deprecated: false,
|
|
113
|
-
required: false,
|
|
114
|
-
schema: {
|
|
115
|
-
type: 'boolean'
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: 'pagination[page]',
|
|
120
|
-
in: 'query',
|
|
121
|
-
description: 'Page number (default: 0)',
|
|
122
|
-
deprecated: false,
|
|
123
|
-
required: false,
|
|
124
|
-
schema: {
|
|
125
|
-
type: 'integer'
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
name: 'pagination[pageSize]',
|
|
130
|
-
in: 'query',
|
|
131
|
-
description: 'Page size (default: 25)',
|
|
132
|
-
deprecated: false,
|
|
133
|
-
required: false,
|
|
134
|
-
schema: {
|
|
135
|
-
type: 'integer'
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: 'pagination[start]',
|
|
140
|
-
in: 'query',
|
|
141
|
-
description: 'Offset value (default: 0)',
|
|
142
|
-
deprecated: false,
|
|
143
|
-
required: false,
|
|
144
|
-
schema: {
|
|
145
|
-
type: 'integer'
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: 'pagination[limit]',
|
|
150
|
-
in: 'query',
|
|
151
|
-
description: 'Number of entities to return (default: 25)',
|
|
152
|
-
deprecated: false,
|
|
153
|
-
required: false,
|
|
154
|
-
schema: {
|
|
155
|
-
type: 'integer'
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: 'fields',
|
|
160
|
-
in: 'query',
|
|
161
|
-
description: 'Fields to return (ex: title,author)',
|
|
162
|
-
deprecated: false,
|
|
163
|
-
required: false,
|
|
164
|
-
schema: {
|
|
165
|
-
type: 'string'
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
name: 'populate',
|
|
170
|
-
in: 'query',
|
|
171
|
-
description: 'Relations to return',
|
|
172
|
-
deprecated: false,
|
|
173
|
-
required: false,
|
|
174
|
-
schema: {
|
|
175
|
-
type: 'string'
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
name: 'filters',
|
|
180
|
-
in: 'query',
|
|
181
|
-
description: 'Filters to apply',
|
|
182
|
-
deprecated: false,
|
|
183
|
-
required: false,
|
|
184
|
-
schema: {
|
|
185
|
-
type: 'object',
|
|
186
|
-
additionalProperties: true
|
|
187
|
-
},
|
|
188
|
-
style: 'deepObject'
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: 'locale',
|
|
192
|
-
in: 'query',
|
|
193
|
-
description: 'Locale to apply',
|
|
194
|
-
deprecated: false,
|
|
195
|
-
required: false,
|
|
196
|
-
schema: {
|
|
197
|
-
type: 'string'
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
];
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* @description A reusable loop for building api endpoint paths and component schemas
|
|
204
|
-
*/ const loopContentTypeNames = (api, callback)=>{
|
|
205
|
-
let result = {};
|
|
206
|
-
for (const contentTypeName of api.ctNames){
|
|
207
|
-
// Get the attributes found on the api's contentType
|
|
208
|
-
const uid = `${api.getter}::${api.name}.${contentTypeName}`;
|
|
209
|
-
const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid);
|
|
210
|
-
// Get the routes for the current api
|
|
211
|
-
const routeInfo = api.getter === 'plugin' ? strapi.plugin(api.name).routes['content-api'] : strapi.api(api.name).routes[contentTypeName];
|
|
212
|
-
// Continue to next iteration if routeInfo is undefined
|
|
213
|
-
if (!routeInfo) {
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
// Uppercase the first letter of the api name
|
|
217
|
-
const apiName = _.upperFirst(api.name);
|
|
218
|
-
// Create a unique name if the api name and contentType name don't match
|
|
219
|
-
const uniqueName = api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;
|
|
220
|
-
const apiInfo = {
|
|
221
|
-
...api,
|
|
222
|
-
routeInfo,
|
|
223
|
-
attributes,
|
|
224
|
-
uniqueName,
|
|
225
|
-
contentTypeInfo,
|
|
226
|
-
kind
|
|
227
|
-
};
|
|
228
|
-
result = {
|
|
229
|
-
...result,
|
|
230
|
-
...callback(apiInfo)
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
return result;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* @description - Builds the Swagger response object for a given api
|
|
238
|
-
*/ const getApiResponse = ({ uniqueName, route, isListOfEntities = false })=>{
|
|
239
|
-
const getSchema = ()=>{
|
|
240
|
-
if (route.method === 'DELETE') {
|
|
241
|
-
return {
|
|
242
|
-
type: 'integer',
|
|
243
|
-
format: 'int64'
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
if (isListOfEntities) {
|
|
247
|
-
return {
|
|
248
|
-
$ref: `#/components/schemas/${pascalCase(uniqueName)}ListResponse`
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
$ref: `#/components/schemas/${pascalCase(uniqueName)}Response`
|
|
253
|
-
};
|
|
254
|
-
};
|
|
255
|
-
const schema = getSchema();
|
|
256
|
-
return {
|
|
257
|
-
200: {
|
|
258
|
-
description: 'OK',
|
|
259
|
-
content: {
|
|
260
|
-
'application/json': {
|
|
261
|
-
schema
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
400: {
|
|
266
|
-
description: 'Bad Request',
|
|
267
|
-
content: {
|
|
268
|
-
'application/json': {
|
|
269
|
-
schema: {
|
|
270
|
-
$ref: '#/components/schemas/Error'
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
401: {
|
|
276
|
-
description: 'Unauthorized',
|
|
277
|
-
content: {
|
|
278
|
-
'application/json': {
|
|
279
|
-
schema: {
|
|
280
|
-
$ref: '#/components/schemas/Error'
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
403: {
|
|
286
|
-
description: 'Forbidden',
|
|
287
|
-
content: {
|
|
288
|
-
'application/json': {
|
|
289
|
-
schema: {
|
|
290
|
-
$ref: '#/components/schemas/Error'
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
404: {
|
|
296
|
-
description: 'Not Found',
|
|
297
|
-
content: {
|
|
298
|
-
'application/json': {
|
|
299
|
-
schema: {
|
|
300
|
-
$ref: '#/components/schemas/Error'
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
500: {
|
|
306
|
-
description: 'Internal Server Error',
|
|
307
|
-
content: {
|
|
308
|
-
'application/json': {
|
|
309
|
-
schema: {
|
|
310
|
-
$ref: '#/components/schemas/Error'
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const hasFindMethod = (handler)=>{
|
|
319
|
-
if (typeof handler === 'string') {
|
|
320
|
-
return handler.split('.').pop() === 'find';
|
|
321
|
-
}
|
|
322
|
-
return false;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* @description Parses a route with ':variable'
|
|
327
|
-
*
|
|
328
|
-
* @param {string} routePath - The route's path property
|
|
329
|
-
* @returns {string}
|
|
330
|
-
*/ const parsePathWithVariables = (routePath)=>{
|
|
331
|
-
const { tokens } = pathToRegexp.parse(routePath);
|
|
332
|
-
return tokens.map((token)=>{
|
|
333
|
-
switch(token.type){
|
|
334
|
-
case 'text':
|
|
335
|
-
return token.value;
|
|
336
|
-
case 'param':
|
|
337
|
-
return `{${token.name}}`;
|
|
338
|
-
case 'wildcard':
|
|
339
|
-
return `{${token.name}}`;
|
|
340
|
-
case 'group':
|
|
341
|
-
// Handle group tokens by mapping them within the same function context
|
|
342
|
-
return `(${parsePathWithVariables(token.tokens.map((t)=>t).join(''))})`;
|
|
343
|
-
default:
|
|
344
|
-
throw new Error(`Unknown token type: ${token.type}`);
|
|
345
|
-
}
|
|
346
|
-
}).join('');
|
|
347
|
-
};
|
|
348
|
-
/**
|
|
349
|
-
* @description Builds the required object for a path parameter
|
|
350
|
-
*
|
|
351
|
-
* @param {string} routePath - The route's path property
|
|
352
|
-
*
|
|
353
|
-
* @returns {object } Swagger path params object
|
|
354
|
-
*/ const getPathParams = (routePath)=>{
|
|
355
|
-
const { tokens } = pathToRegexp.parse(routePath);
|
|
356
|
-
return tokens.reduce((acc, param)=>{
|
|
357
|
-
// Skip non-parameter tokens
|
|
358
|
-
if (param.type !== 'param') {
|
|
359
|
-
return acc;
|
|
360
|
-
}
|
|
361
|
-
acc.push({
|
|
362
|
-
name: `${param.name}`,
|
|
363
|
-
in: 'path',
|
|
364
|
-
description: '',
|
|
365
|
-
deprecated: false,
|
|
366
|
-
required: true,
|
|
367
|
-
schema: {
|
|
368
|
-
type: 'number'
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
return acc;
|
|
372
|
-
}, []);
|
|
373
|
-
};
|
|
374
|
-
const getPathWithPrefix = (prefix, route)=>{
|
|
375
|
-
// When the prefix is set on the routes and
|
|
376
|
-
// the current route is not trying to remove it
|
|
377
|
-
if (prefix && !_.has(route.config, 'prefix')) {
|
|
378
|
-
// Add the prefix to the path
|
|
379
|
-
return prefix.concat(route.path);
|
|
380
|
-
}
|
|
381
|
-
// Otherwise just return path
|
|
382
|
-
return route.path;
|
|
383
|
-
};
|
|
384
|
-
/**
|
|
385
|
-
* @description Gets all paths based on routes
|
|
386
|
-
*
|
|
387
|
-
* @param {object} apiInfo
|
|
388
|
-
* @property {object} apiInfo.routeInfo - The api routes object
|
|
389
|
-
* @property {string} apiInfo.uniqueName - Content type name | Api name + Content type name
|
|
390
|
-
* @property {object} apiInfo.contentTypeInfo - The info object found on content type schemas
|
|
391
|
-
*
|
|
392
|
-
* @returns {object}
|
|
393
|
-
*/ const getPaths = ({ routeInfo, uniqueName, contentTypeInfo, kind })=>{
|
|
394
|
-
// Get the routes for the current content type
|
|
395
|
-
const contentTypeRoutes = routeInfo.routes.filter((route)=>{
|
|
396
|
-
return route.path.includes(contentTypeInfo.pluralName) || route.path.includes(contentTypeInfo.singularName);
|
|
397
|
-
});
|
|
398
|
-
const paths = contentTypeRoutes.reduce((acc, route)=>{
|
|
399
|
-
// TODO: Find a more reliable way to determine list of entities vs a single entity
|
|
400
|
-
const isListOfEntities = hasFindMethod(route.handler);
|
|
401
|
-
const methodVerb = route.method.toLowerCase();
|
|
402
|
-
const hasPathParams = route.path.includes('/:');
|
|
403
|
-
const pathWithPrefix = getPathWithPrefix(routeInfo.prefix, route);
|
|
404
|
-
const routePath = hasPathParams ? parsePathWithVariables(pathWithPrefix) : pathWithPrefix;
|
|
405
|
-
const responses = getApiResponse({
|
|
406
|
-
uniqueName,
|
|
407
|
-
route,
|
|
408
|
-
isListOfEntities: kind !== 'singleType' && isListOfEntities
|
|
409
|
-
});
|
|
410
|
-
const swaggerConfig = {
|
|
411
|
-
responses,
|
|
412
|
-
tags: [
|
|
413
|
-
_.upperFirst(uniqueName)
|
|
414
|
-
],
|
|
415
|
-
parameters: [],
|
|
416
|
-
operationId: `${methodVerb}${routePath}`
|
|
417
|
-
};
|
|
418
|
-
if (isListOfEntities) {
|
|
419
|
-
swaggerConfig.parameters?.push(...params);
|
|
420
|
-
}
|
|
421
|
-
if (hasPathParams) {
|
|
422
|
-
const pathParams = getPathParams(route.path);
|
|
423
|
-
swaggerConfig.parameters?.push(...pathParams);
|
|
424
|
-
}
|
|
425
|
-
if ([
|
|
426
|
-
'post',
|
|
427
|
-
'put'
|
|
428
|
-
].includes(methodVerb)) {
|
|
429
|
-
const refName = 'Request';
|
|
430
|
-
const requestBody = {
|
|
431
|
-
required: true,
|
|
432
|
-
content: {
|
|
433
|
-
'application/json': {
|
|
434
|
-
schema: {
|
|
435
|
-
$ref: `#/components/schemas/${pascalCase(uniqueName)}${refName}`
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
swaggerConfig.requestBody = requestBody;
|
|
441
|
-
}
|
|
442
|
-
_.set(acc, `${routePath}.${methodVerb}`, swaggerConfig);
|
|
443
|
-
return acc;
|
|
444
|
-
}, {});
|
|
445
|
-
return paths;
|
|
446
|
-
};
|
|
447
|
-
/**
|
|
448
|
-
* @description - Builds the Swagger paths object for each api
|
|
449
|
-
*/ const buildApiEndpointPath = (api)=>{
|
|
450
|
-
// A reusable loop for building paths and component schemas
|
|
451
|
-
// Uses the api param to build a new set of params for each content type
|
|
452
|
-
// Passes these new params to the function provided
|
|
453
|
-
return loopContentTypeNames(api, getPaths);
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* @description Determines the format of the data response
|
|
458
|
-
*
|
|
459
|
-
* @param {boolean} isListOfEntities - Checks for a multiple entities
|
|
460
|
-
* @param {object} attributes - The attributes found on a contentType
|
|
461
|
-
|
|
462
|
-
* @returns object | array of attributes
|
|
463
|
-
*/ var getSchemaData = ((isListOfEntities, attributes)=>{
|
|
464
|
-
if (isListOfEntities) {
|
|
465
|
-
return {
|
|
466
|
-
type: 'array',
|
|
467
|
-
items: {
|
|
468
|
-
type: 'object',
|
|
469
|
-
properties: {
|
|
470
|
-
id: {
|
|
471
|
-
type: 'number'
|
|
472
|
-
},
|
|
473
|
-
documentId: {
|
|
474
|
-
type: 'string'
|
|
475
|
-
},
|
|
476
|
-
...attributes
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
return {
|
|
482
|
-
type: 'object',
|
|
483
|
-
properties: {
|
|
484
|
-
id: {
|
|
485
|
-
type: 'number'
|
|
486
|
-
},
|
|
487
|
-
documentId: {
|
|
488
|
-
type: 'string'
|
|
489
|
-
},
|
|
490
|
-
...attributes
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* @description - Convert attribute component names to OpenAPI component names
|
|
497
|
-
*
|
|
498
|
-
* @returns OpenAPI component name
|
|
499
|
-
*/ const convertComponentName = (component, isRef = false)=>{
|
|
500
|
-
const cleanComponentName = `${pascalCase(component)}Component`;
|
|
501
|
-
if (isRef) {
|
|
502
|
-
return `#/components/schemas/${cleanComponentName}`;
|
|
503
|
-
}
|
|
504
|
-
return cleanComponentName;
|
|
505
|
-
};
|
|
506
|
-
/**
|
|
507
|
-
* @description - Converts types found on attributes to OpenAPI acceptable data types
|
|
508
|
-
*
|
|
509
|
-
* @returns Attributes using OpenAPI acceptable data types
|
|
510
|
-
*/ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = false, didAddStrapiComponentsToSchemas })=>{
|
|
511
|
-
const schemaAttributes = {};
|
|
512
|
-
for (const prop of Object.keys(attributes)){
|
|
513
|
-
const attribute = attributes[prop];
|
|
514
|
-
switch(attribute.type){
|
|
515
|
-
case 'password':
|
|
516
|
-
{
|
|
517
|
-
if (!isRequest) {
|
|
518
|
-
break;
|
|
519
|
-
}
|
|
520
|
-
schemaAttributes[prop] = {
|
|
521
|
-
type: 'string',
|
|
522
|
-
format: 'password',
|
|
523
|
-
example: '*******'
|
|
524
|
-
};
|
|
525
|
-
break;
|
|
526
|
-
}
|
|
527
|
-
case 'email':
|
|
528
|
-
{
|
|
529
|
-
schemaAttributes[prop] = {
|
|
530
|
-
type: 'string',
|
|
531
|
-
format: 'email'
|
|
532
|
-
};
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
case 'string':
|
|
536
|
-
case 'text':
|
|
537
|
-
case 'richtext':
|
|
538
|
-
{
|
|
539
|
-
schemaAttributes[prop] = {
|
|
540
|
-
type: 'string'
|
|
541
|
-
};
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
case 'timestamp':
|
|
545
|
-
{
|
|
546
|
-
schemaAttributes[prop] = {
|
|
547
|
-
type: 'string',
|
|
548
|
-
format: 'timestamp',
|
|
549
|
-
example: Date.now()
|
|
550
|
-
};
|
|
551
|
-
break;
|
|
552
|
-
}
|
|
553
|
-
case 'time':
|
|
554
|
-
{
|
|
555
|
-
schemaAttributes[prop] = {
|
|
556
|
-
type: 'string',
|
|
557
|
-
format: 'time',
|
|
558
|
-
example: '12:54.000'
|
|
559
|
-
};
|
|
560
|
-
break;
|
|
561
|
-
}
|
|
562
|
-
case 'date':
|
|
563
|
-
{
|
|
564
|
-
schemaAttributes[prop] = {
|
|
565
|
-
type: 'string',
|
|
566
|
-
format: 'date'
|
|
567
|
-
};
|
|
568
|
-
break;
|
|
569
|
-
}
|
|
570
|
-
case 'datetime':
|
|
571
|
-
{
|
|
572
|
-
schemaAttributes[prop] = {
|
|
573
|
-
type: 'string',
|
|
574
|
-
format: 'date-time'
|
|
575
|
-
};
|
|
576
|
-
break;
|
|
577
|
-
}
|
|
578
|
-
case 'boolean':
|
|
579
|
-
{
|
|
580
|
-
schemaAttributes[prop] = {
|
|
581
|
-
type: 'boolean'
|
|
582
|
-
};
|
|
583
|
-
break;
|
|
584
|
-
}
|
|
585
|
-
case 'enumeration':
|
|
586
|
-
{
|
|
587
|
-
schemaAttributes[prop] = {
|
|
588
|
-
type: 'string',
|
|
589
|
-
enum: [
|
|
590
|
-
...attribute.enum
|
|
591
|
-
]
|
|
592
|
-
};
|
|
593
|
-
break;
|
|
594
|
-
}
|
|
595
|
-
case 'decimal':
|
|
596
|
-
case 'float':
|
|
597
|
-
{
|
|
598
|
-
schemaAttributes[prop] = {
|
|
599
|
-
type: 'number',
|
|
600
|
-
format: 'float'
|
|
601
|
-
};
|
|
602
|
-
break;
|
|
603
|
-
}
|
|
604
|
-
case 'integer':
|
|
605
|
-
{
|
|
606
|
-
schemaAttributes[prop] = {
|
|
607
|
-
type: 'integer'
|
|
608
|
-
};
|
|
609
|
-
break;
|
|
610
|
-
}
|
|
611
|
-
case 'biginteger':
|
|
612
|
-
{
|
|
613
|
-
schemaAttributes[prop] = {
|
|
614
|
-
type: 'string',
|
|
615
|
-
pattern: '^\\d*$',
|
|
616
|
-
example: '123456789'
|
|
617
|
-
};
|
|
618
|
-
break;
|
|
619
|
-
}
|
|
620
|
-
case 'json':
|
|
621
|
-
case 'blocks':
|
|
622
|
-
{
|
|
623
|
-
schemaAttributes[prop] = {};
|
|
624
|
-
break;
|
|
625
|
-
}
|
|
626
|
-
case 'uid':
|
|
627
|
-
{
|
|
628
|
-
schemaAttributes[prop] = {
|
|
629
|
-
type: 'string'
|
|
630
|
-
};
|
|
631
|
-
break;
|
|
632
|
-
}
|
|
633
|
-
case 'component':
|
|
634
|
-
{
|
|
635
|
-
const componentAttributes = strapi.components[attribute.component].attributes;
|
|
636
|
-
const rawComponentSchema = {
|
|
637
|
-
type: 'object',
|
|
638
|
-
properties: {
|
|
639
|
-
...isRequest ? {} : {
|
|
640
|
-
id: {
|
|
641
|
-
type: 'number'
|
|
642
|
-
}
|
|
643
|
-
},
|
|
644
|
-
...cleanSchemaAttributes(componentAttributes, {
|
|
645
|
-
typeMap,
|
|
646
|
-
isRequest,
|
|
647
|
-
didAddStrapiComponentsToSchemas
|
|
648
|
-
})
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
const refComponentSchema = {
|
|
652
|
-
$ref: convertComponentName(attribute.component, true)
|
|
653
|
-
};
|
|
654
|
-
const componentExists = didAddStrapiComponentsToSchemas(convertComponentName(attribute.component), rawComponentSchema);
|
|
655
|
-
const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;
|
|
656
|
-
if (attribute.repeatable) {
|
|
657
|
-
schemaAttributes[prop] = {
|
|
658
|
-
type: 'array',
|
|
659
|
-
items: finalComponentSchema
|
|
660
|
-
};
|
|
661
|
-
} else {
|
|
662
|
-
schemaAttributes[prop] = finalComponentSchema;
|
|
663
|
-
}
|
|
664
|
-
break;
|
|
665
|
-
}
|
|
666
|
-
case 'dynamiczone':
|
|
667
|
-
{
|
|
668
|
-
const components = attribute.components.map((component)=>{
|
|
669
|
-
const componentAttributes = strapi.components[component].attributes;
|
|
670
|
-
const rawComponentSchema = {
|
|
671
|
-
type: 'object',
|
|
672
|
-
properties: {
|
|
673
|
-
...isRequest ? {} : {
|
|
674
|
-
id: {
|
|
675
|
-
type: 'number'
|
|
676
|
-
}
|
|
677
|
-
},
|
|
678
|
-
__component: {
|
|
679
|
-
type: 'string',
|
|
680
|
-
enum: [
|
|
681
|
-
component
|
|
682
|
-
]
|
|
683
|
-
},
|
|
684
|
-
...cleanSchemaAttributes(componentAttributes, {
|
|
685
|
-
typeMap,
|
|
686
|
-
isRequest,
|
|
687
|
-
didAddStrapiComponentsToSchemas
|
|
688
|
-
})
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
const refComponentSchema = {
|
|
692
|
-
$ref: convertComponentName(component, true)
|
|
693
|
-
};
|
|
694
|
-
const componentExists = didAddStrapiComponentsToSchemas(convertComponentName(component), rawComponentSchema);
|
|
695
|
-
const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;
|
|
696
|
-
return finalComponentSchema;
|
|
697
|
-
});
|
|
698
|
-
let discriminator;
|
|
699
|
-
if (components.every((component)=>Object.hasOwn(component, '$ref'))) {
|
|
700
|
-
discriminator = {
|
|
701
|
-
propertyName: '__component',
|
|
702
|
-
mapping: attribute.components.reduce((acc, component)=>{
|
|
703
|
-
acc[component] = convertComponentName(component, true);
|
|
704
|
-
return acc;
|
|
705
|
-
}, {})
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
schemaAttributes[prop] = {
|
|
709
|
-
type: 'array',
|
|
710
|
-
items: {
|
|
711
|
-
anyOf: components
|
|
712
|
-
},
|
|
713
|
-
discriminator
|
|
714
|
-
};
|
|
715
|
-
break;
|
|
716
|
-
}
|
|
717
|
-
case 'media':
|
|
718
|
-
{
|
|
719
|
-
const imageAttributes = strapi.contentType('plugin::upload.file').attributes;
|
|
720
|
-
const isListOfEntities = attribute.multiple ?? false;
|
|
721
|
-
if (isRequest) {
|
|
722
|
-
const oneOfType = {
|
|
723
|
-
oneOf: [
|
|
724
|
-
{
|
|
725
|
-
type: 'integer'
|
|
726
|
-
},
|
|
727
|
-
{
|
|
728
|
-
type: 'string'
|
|
729
|
-
}
|
|
730
|
-
],
|
|
731
|
-
example: 'string or id'
|
|
732
|
-
};
|
|
733
|
-
schemaAttributes[prop] = isListOfEntities ? {
|
|
734
|
-
type: 'array',
|
|
735
|
-
items: oneOfType
|
|
736
|
-
} : oneOfType;
|
|
737
|
-
break;
|
|
738
|
-
}
|
|
739
|
-
schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(imageAttributes, {
|
|
740
|
-
typeMap,
|
|
741
|
-
didAddStrapiComponentsToSchemas
|
|
742
|
-
}));
|
|
743
|
-
break;
|
|
744
|
-
}
|
|
745
|
-
case 'relation':
|
|
746
|
-
{
|
|
747
|
-
const isListOfEntities = attribute.relation.includes('ToMany');
|
|
748
|
-
if (isRequest) {
|
|
749
|
-
const oneOfType = {
|
|
750
|
-
oneOf: [
|
|
751
|
-
{
|
|
752
|
-
type: 'integer'
|
|
753
|
-
},
|
|
754
|
-
{
|
|
755
|
-
type: 'string'
|
|
756
|
-
}
|
|
757
|
-
],
|
|
758
|
-
example: 'string or id'
|
|
759
|
-
};
|
|
760
|
-
schemaAttributes[prop] = isListOfEntities ? {
|
|
761
|
-
type: 'array',
|
|
762
|
-
items: oneOfType
|
|
763
|
-
} : oneOfType;
|
|
764
|
-
break;
|
|
765
|
-
}
|
|
766
|
-
if (!('target' in attribute) || !attribute.target || typeMap.has(attribute.target)) {
|
|
767
|
-
schemaAttributes[prop] = getSchemaData(isListOfEntities, {});
|
|
768
|
-
break;
|
|
769
|
-
}
|
|
770
|
-
typeMap.set(attribute.target, true);
|
|
771
|
-
const targetAttributes = strapi.contentType(attribute.target).attributes;
|
|
772
|
-
schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(targetAttributes, {
|
|
773
|
-
typeMap,
|
|
774
|
-
isRequest,
|
|
775
|
-
didAddStrapiComponentsToSchemas
|
|
776
|
-
}));
|
|
777
|
-
break;
|
|
778
|
-
}
|
|
779
|
-
default:
|
|
780
|
-
{
|
|
781
|
-
// @ts-expect-error - This is a catch all for any other types
|
|
782
|
-
throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
return schemaAttributes;
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
const getRequiredAttributes = (allAttributes)=>{
|
|
790
|
-
const requiredAttributes = [];
|
|
791
|
-
for(const key in allAttributes){
|
|
792
|
-
if (allAttributes[key].required) {
|
|
793
|
-
requiredAttributes.push(key);
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
return requiredAttributes;
|
|
797
|
-
};
|
|
798
|
-
/**
|
|
799
|
-
* @description Get all open api schema objects for a given content type
|
|
800
|
-
*
|
|
801
|
-
* @param {object} apiInfo
|
|
802
|
-
* @property {string} apiInfo.uniqueName - Api name | Api name + Content type name
|
|
803
|
-
* @property {object} apiInfo.attributes - Attributes on content type
|
|
804
|
-
* @property {object} apiInfo.routeInfo - The routes for the api
|
|
805
|
-
*
|
|
806
|
-
* @returns {object} Open API schemas
|
|
807
|
-
*/ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName })=>{
|
|
808
|
-
// Store response and request schemas in an object
|
|
809
|
-
let strapiComponentSchemas = {};
|
|
810
|
-
const schemas = {};
|
|
811
|
-
const typeName = pascalCase(uniqueName);
|
|
812
|
-
// adds a ComponentSchema to the Schemas so it can be used as Ref
|
|
813
|
-
const didAddStrapiComponentsToSchemas = (schemaName, schema)=>{
|
|
814
|
-
if (!Object.keys(schema) || !Object.keys(schema.properties)) return false;
|
|
815
|
-
// Add the Strapi components to the schema
|
|
816
|
-
strapiComponentSchemas = {
|
|
817
|
-
...strapiComponentSchemas,
|
|
818
|
-
[schemaName]: schema
|
|
819
|
-
};
|
|
820
|
-
return true;
|
|
821
|
-
};
|
|
822
|
-
// Get all the route methods
|
|
823
|
-
const routeMethods = routeInfo.routes.map((route)=>route.method);
|
|
824
|
-
const attributesToOmit = [
|
|
825
|
-
'createdAt',
|
|
826
|
-
'updatedAt',
|
|
827
|
-
'publishedAt',
|
|
828
|
-
'publishedBy',
|
|
829
|
-
'updatedBy',
|
|
830
|
-
'createdBy'
|
|
831
|
-
];
|
|
832
|
-
const attributesForRequest = _.omit(attributes, attributesToOmit);
|
|
833
|
-
// Get a list of required attribute names
|
|
834
|
-
const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);
|
|
835
|
-
// Build the request schemas when the route has POST or PUT methods
|
|
836
|
-
if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {
|
|
837
|
-
// Build localization requests schemas
|
|
838
|
-
// Build the request schema
|
|
839
|
-
Object.assign(schemas, {
|
|
840
|
-
[`${typeName}Request`]: {
|
|
841
|
-
type: 'object',
|
|
842
|
-
required: [
|
|
843
|
-
'data'
|
|
844
|
-
],
|
|
845
|
-
properties: {
|
|
846
|
-
data: {
|
|
847
|
-
...requiredRequestAttributes.length && {
|
|
848
|
-
required: requiredRequestAttributes
|
|
849
|
-
},
|
|
850
|
-
type: 'object',
|
|
851
|
-
properties: cleanSchemaAttributes(attributesForRequest, {
|
|
852
|
-
isRequest: true,
|
|
853
|
-
didAddStrapiComponentsToSchemas
|
|
854
|
-
})
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
// Check for routes that need to return a list
|
|
861
|
-
const hasListOfEntities = routeInfo.routes.filter((route)=>hasFindMethod(route.handler)).length;
|
|
862
|
-
if (hasListOfEntities) {
|
|
863
|
-
// Build the list response schema
|
|
864
|
-
Object.assign(schemas, {
|
|
865
|
-
[`${typeName}ListResponse`]: {
|
|
866
|
-
type: 'object',
|
|
867
|
-
properties: {
|
|
868
|
-
data: {
|
|
869
|
-
type: 'array',
|
|
870
|
-
items: {
|
|
871
|
-
$ref: `#/components/schemas/${typeName}`
|
|
872
|
-
}
|
|
873
|
-
},
|
|
874
|
-
meta: {
|
|
875
|
-
type: 'object',
|
|
876
|
-
properties: {
|
|
877
|
-
pagination: {
|
|
878
|
-
type: 'object',
|
|
879
|
-
properties: {
|
|
880
|
-
page: {
|
|
881
|
-
type: 'integer'
|
|
882
|
-
},
|
|
883
|
-
pageSize: {
|
|
884
|
-
type: 'integer',
|
|
885
|
-
minimum: 25
|
|
886
|
-
},
|
|
887
|
-
pageCount: {
|
|
888
|
-
type: 'integer',
|
|
889
|
-
maximum: 1
|
|
890
|
-
},
|
|
891
|
-
total: {
|
|
892
|
-
type: 'integer'
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
const requiredAttributes = getRequiredAttributes(attributes);
|
|
903
|
-
// Build the response schema
|
|
904
|
-
Object.assign(schemas, {
|
|
905
|
-
[`${typeName}`]: {
|
|
906
|
-
type: 'object',
|
|
907
|
-
...requiredAttributes.length && {
|
|
908
|
-
required: requiredAttributes
|
|
909
|
-
},
|
|
910
|
-
properties: {
|
|
911
|
-
id: {
|
|
912
|
-
type: 'number'
|
|
913
|
-
},
|
|
914
|
-
documentId: {
|
|
915
|
-
type: 'string'
|
|
916
|
-
},
|
|
917
|
-
...cleanSchemaAttributes(attributes, {
|
|
918
|
-
didAddStrapiComponentsToSchemas
|
|
919
|
-
})
|
|
920
|
-
}
|
|
921
|
-
},
|
|
922
|
-
[`${typeName}Response`]: {
|
|
923
|
-
type: 'object',
|
|
924
|
-
properties: {
|
|
925
|
-
data: {
|
|
926
|
-
$ref: `#/components/schemas/${typeName}`
|
|
927
|
-
},
|
|
928
|
-
meta: {
|
|
929
|
-
type: 'object'
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
});
|
|
934
|
-
return {
|
|
935
|
-
...schemas,
|
|
936
|
-
...strapiComponentSchemas
|
|
937
|
-
};
|
|
938
|
-
};
|
|
939
|
-
const buildComponentSchema = (api)=>{
|
|
940
|
-
// A reusable loop for building paths and component schemas
|
|
941
|
-
// Uses the api param to build a new set of params for each content type
|
|
942
|
-
// Passes these new params to the function provided
|
|
943
|
-
return loopContentTypeNames(api, getAllSchemasForContentType);
|
|
944
|
-
};
|
|
945
|
-
|
|
946
|
-
const getPluginsThatNeedDocumentation = (config)=>{
|
|
947
|
-
// Default plugins that need documentation generated
|
|
948
|
-
const defaultPlugins = [
|
|
949
|
-
'upload',
|
|
950
|
-
'users-permissions'
|
|
951
|
-
];
|
|
952
|
-
// User specified plugins that need documentation generated
|
|
953
|
-
const userPluginsConfig = config['x-strapi-config'].plugins;
|
|
954
|
-
if (userPluginsConfig === null) {
|
|
955
|
-
// The user hasn't specified any plugins to document, use the defaults
|
|
956
|
-
return defaultPlugins;
|
|
957
|
-
}
|
|
958
|
-
if (userPluginsConfig.length) {
|
|
959
|
-
// The user has specified certain plugins to document, use them
|
|
960
|
-
return userPluginsConfig;
|
|
961
|
-
}
|
|
962
|
-
// The user has specified that no plugins should be documented
|
|
963
|
-
return [];
|
|
964
|
-
};
|
|
965
|
-
|
|
966
|
-
const createService$1 = ({ strapi })=>{
|
|
967
|
-
const config = strapi.config.get('plugin::documentation');
|
|
968
|
-
const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(config);
|
|
969
|
-
const overrideService = getService('override');
|
|
970
|
-
return {
|
|
971
|
-
getDocumentationVersion () {
|
|
972
|
-
return config.info.version;
|
|
973
|
-
},
|
|
974
|
-
getFullDocumentationPath () {
|
|
975
|
-
return path.join(strapi.dirs.app.extensions, 'documentation', 'documentation');
|
|
976
|
-
},
|
|
977
|
-
getDocumentationVersions () {
|
|
978
|
-
return fs.readdirSync(this.getFullDocumentationPath()).map((version)=>{
|
|
979
|
-
try {
|
|
980
|
-
const filePath = path.resolve(this.getFullDocumentationPath(), version, 'full_documentation.json');
|
|
981
|
-
const doc = JSON.parse(fs.readFileSync(filePath).toString());
|
|
982
|
-
const generatedDate = doc.info['x-generation-date'];
|
|
983
|
-
return {
|
|
984
|
-
version,
|
|
985
|
-
generatedDate,
|
|
986
|
-
url: ''
|
|
987
|
-
};
|
|
988
|
-
} catch (err) {
|
|
989
|
-
return null;
|
|
990
|
-
}
|
|
991
|
-
}).filter((x)=>x);
|
|
992
|
-
},
|
|
993
|
-
/**
|
|
994
|
-
* Returns settings stored in core-store
|
|
995
|
-
*/ async getDocumentationAccess () {
|
|
996
|
-
const { restrictedAccess } = await strapi.store({
|
|
997
|
-
environment: '',
|
|
998
|
-
type: 'plugin',
|
|
999
|
-
name: 'documentation',
|
|
1000
|
-
key: 'config'
|
|
1001
|
-
}).get();
|
|
1002
|
-
return {
|
|
1003
|
-
restrictedAccess
|
|
1004
|
-
};
|
|
1005
|
-
},
|
|
1006
|
-
getApiDocumentationPath (api) {
|
|
1007
|
-
if (api.getter === 'plugin') {
|
|
1008
|
-
return path.join(strapi.dirs.app.extensions, api.name, 'documentation');
|
|
1009
|
-
}
|
|
1010
|
-
return path.join(strapi.dirs.app.api, api.name, 'documentation');
|
|
1011
|
-
},
|
|
1012
|
-
async deleteDocumentation (version) {
|
|
1013
|
-
const apis = this.getPluginAndApiInfo();
|
|
1014
|
-
for (const api of apis){
|
|
1015
|
-
await fs.remove(path.join(this.getApiDocumentationPath(api), version));
|
|
1016
|
-
}
|
|
1017
|
-
await fs.remove(path.join(this.getFullDocumentationPath(), version));
|
|
1018
|
-
},
|
|
1019
|
-
getPluginAndApiInfo () {
|
|
1020
|
-
const pluginsToDocument = pluginsThatNeedDocumentation.map((plugin)=>{
|
|
1021
|
-
return {
|
|
1022
|
-
name: plugin,
|
|
1023
|
-
getter: 'plugin',
|
|
1024
|
-
ctNames: Object.keys(strapi.plugin(plugin).contentTypes)
|
|
1025
|
-
};
|
|
1026
|
-
});
|
|
1027
|
-
const apisToDocument = Object.keys(strapi.apis).map((api)=>{
|
|
1028
|
-
return {
|
|
1029
|
-
name: api,
|
|
1030
|
-
getter: 'api',
|
|
1031
|
-
ctNames: Object.keys(strapi.api(api).contentTypes)
|
|
1032
|
-
};
|
|
1033
|
-
});
|
|
1034
|
-
return [
|
|
1035
|
-
...apisToDocument,
|
|
1036
|
-
...pluginsToDocument
|
|
1037
|
-
];
|
|
1038
|
-
},
|
|
1039
|
-
/**
|
|
1040
|
-
* @description - Creates the Swagger json files
|
|
1041
|
-
*/ async generateFullDoc (versionOpt) {
|
|
1042
|
-
const version = versionOpt ?? this.getDocumentationVersion();
|
|
1043
|
-
const apis = this.getPluginAndApiInfo();
|
|
1044
|
-
const apisThatNeedGeneratedDocumentation = apis.filter(({ name })=>!overrideService.isEnabled(name));
|
|
1045
|
-
// Initialize the generated documentation with defaults
|
|
1046
|
-
const generatedDocumentation = await produce(config, async (draft)=>{
|
|
1047
|
-
if (draft.servers?.length === 0) {
|
|
1048
|
-
// When no servers found set the defaults
|
|
1049
|
-
const serverUrl = strapi.config.get('server.absoluteUrl');
|
|
1050
|
-
const apiPath = strapi.config.get('api.rest.prefix');
|
|
1051
|
-
draft.servers = [
|
|
1052
|
-
{
|
|
1053
|
-
url: `${serverUrl}${apiPath}`,
|
|
1054
|
-
description: 'Development server'
|
|
1055
|
-
}
|
|
1056
|
-
];
|
|
1057
|
-
}
|
|
1058
|
-
if (!draft.components) {
|
|
1059
|
-
draft.components = {};
|
|
1060
|
-
}
|
|
1061
|
-
// Set the generated date
|
|
1062
|
-
draft.info['x-generation-date'] = new Date().toISOString();
|
|
1063
|
-
// Set the plugins that need documentation
|
|
1064
|
-
draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;
|
|
1065
|
-
// Delete the mutateDocumentation key from the config so it doesn't end up in the spec
|
|
1066
|
-
delete draft['x-strapi-config'].mutateDocumentation;
|
|
1067
|
-
// Generate the documentation for each api and update the generatedDocumentation
|
|
1068
|
-
for (const api of apisThatNeedGeneratedDocumentation){
|
|
1069
|
-
const newApiPath = buildApiEndpointPath(api);
|
|
1070
|
-
const generatedSchemas = buildComponentSchema(api);
|
|
1071
|
-
if (generatedSchemas) {
|
|
1072
|
-
draft.components.schemas = {
|
|
1073
|
-
...draft.components.schemas,
|
|
1074
|
-
...generatedSchemas
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
if (newApiPath) {
|
|
1078
|
-
draft.paths = {
|
|
1079
|
-
...draft.paths,
|
|
1080
|
-
...newApiPath
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
// When overrides are present update the generatedDocumentation
|
|
1085
|
-
if (overrideService.registeredOverrides.length > 0) {
|
|
1086
|
-
overrideService.registeredOverrides.forEach((override)=>{
|
|
1087
|
-
// Only run the overrrides when no override version is provided,
|
|
1088
|
-
// or when the generated documentation version matches the override version
|
|
1089
|
-
if (!override?.info?.version || override.info.version === version) {
|
|
1090
|
-
if (override.tags) {
|
|
1091
|
-
// Merge override tags with the generated tags
|
|
1092
|
-
draft.tags = draft.tags || [];
|
|
1093
|
-
draft.tags.push(...override.tags);
|
|
1094
|
-
}
|
|
1095
|
-
if (override.paths) {
|
|
1096
|
-
// Merge override paths with the generated paths
|
|
1097
|
-
// The override will add a new path or replace the value of an existing path
|
|
1098
|
-
draft.paths = {
|
|
1099
|
-
...draft.paths,
|
|
1100
|
-
...override.paths
|
|
1101
|
-
};
|
|
1102
|
-
}
|
|
1103
|
-
if (override.components) {
|
|
1104
|
-
const keys = Object.keys(override.components);
|
|
1105
|
-
keys.forEach((overrideKey)=>{
|
|
1106
|
-
draft.components = draft.components || {};
|
|
1107
|
-
const overrideValue = override.components?.[overrideKey];
|
|
1108
|
-
const originalValue = draft.components?.[overrideKey];
|
|
1109
|
-
Object.assign(draft.components, {
|
|
1110
|
-
[overrideKey]: {
|
|
1111
|
-
...originalValue,
|
|
1112
|
-
...overrideValue
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
});
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
});
|
|
1121
|
-
// Escape hatch, allow the user to provide a mutateDocumentation function that can alter any part of
|
|
1122
|
-
// the generated documentation before it is written to the file system
|
|
1123
|
-
const userMutatesDocumentation = config['x-strapi-config'].mutateDocumentation;
|
|
1124
|
-
const finalDocumentation = userMutatesDocumentation ? produce(generatedDocumentation, userMutatesDocumentation) : generatedDocumentation;
|
|
1125
|
-
// Get the file path for the final documentation
|
|
1126
|
-
const fullDocJsonPath = path.join(this.getFullDocumentationPath(), version, 'full_documentation.json');
|
|
1127
|
-
// Write the documentation to the file system
|
|
1128
|
-
await fs.ensureFile(fullDocJsonPath);
|
|
1129
|
-
await fs.writeJson(fullDocJsonPath, finalDocumentation, {
|
|
1130
|
-
spaces: 2
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
const createService = ({ strapi })=>{
|
|
1137
|
-
const registeredOverrides = [];
|
|
1138
|
-
const excludedFromGeneration = [];
|
|
1139
|
-
return {
|
|
1140
|
-
registeredOverrides,
|
|
1141
|
-
excludedFromGeneration,
|
|
1142
|
-
/**
|
|
1143
|
-
*
|
|
1144
|
-
* @param {(string | string[])} api - The name of the api or and array of apis to exclude from generation
|
|
1145
|
-
*/ excludeFromGeneration (api) {
|
|
1146
|
-
if (Array.isArray(api)) {
|
|
1147
|
-
excludedFromGeneration.push(...api);
|
|
1148
|
-
return;
|
|
1149
|
-
}
|
|
1150
|
-
excludedFromGeneration.push(api);
|
|
1151
|
-
},
|
|
1152
|
-
isEnabled (name) {
|
|
1153
|
-
return excludedFromGeneration.includes(name);
|
|
1154
|
-
},
|
|
1155
|
-
registerOverride (override, opts) {
|
|
1156
|
-
const { pluginOrigin, excludeFromGeneration = [] } = opts ?? {};
|
|
1157
|
-
const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(strapi.config.get('plugin::documentation'));
|
|
1158
|
-
// Don't apply the override if the plugin is not in the list of plugins that need documentation
|
|
1159
|
-
if (pluginOrigin && !pluginsThatNeedDocumentation.includes(pluginOrigin)) return;
|
|
1160
|
-
if (excludeFromGeneration.length) {
|
|
1161
|
-
this.excludeFromGeneration(excludeFromGeneration);
|
|
1162
|
-
}
|
|
1163
|
-
let overrideToRegister = override;
|
|
1164
|
-
// Parse yaml if we receive a string
|
|
1165
|
-
if (typeof override === 'string') {
|
|
1166
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1167
|
-
overrideToRegister = require('yaml').parse(overrideToRegister);
|
|
1168
|
-
}
|
|
1169
|
-
// receive an object we can register it directly
|
|
1170
|
-
registeredOverrides.push(overrideToRegister);
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
};
|
|
1174
|
-
|
|
1175
|
-
// import type { Common } from '@strapi/types';
|
|
1176
|
-
var services = {
|
|
1177
|
-
documentation: createService$1,
|
|
1178
|
-
override: createService
|
|
1179
|
-
};
|
|
1180
|
-
|
|
1181
|
-
var restrictAccess = (async (ctx, next)=>{
|
|
1182
|
-
const pluginStore = strapi.store({
|
|
1183
|
-
type: 'plugin',
|
|
1184
|
-
name: 'documentation'
|
|
1185
|
-
});
|
|
1186
|
-
const config = await pluginStore.get({
|
|
1187
|
-
key: 'config'
|
|
1188
|
-
});
|
|
1189
|
-
if (!config.restrictedAccess) {
|
|
1190
|
-
return next();
|
|
1191
|
-
}
|
|
1192
|
-
if (!ctx.session || !ctx.session.documentation || !ctx.session.documentation.logged) {
|
|
1193
|
-
const querystring = ctx.querystring ? `?${ctx.querystring}` : '';
|
|
1194
|
-
return ctx.redirect(`${strapi.config.server.url}/documentation/login${querystring}`);
|
|
1195
|
-
}
|
|
1196
|
-
// Execute the action.
|
|
1197
|
-
return next();
|
|
1198
|
-
});
|
|
1199
|
-
|
|
1200
|
-
var routes = [
|
|
1201
|
-
{
|
|
1202
|
-
method: 'GET',
|
|
1203
|
-
path: '/',
|
|
1204
|
-
handler: 'documentation.index',
|
|
1205
|
-
config: {
|
|
1206
|
-
auth: false,
|
|
1207
|
-
middlewares: [
|
|
1208
|
-
restrictAccess
|
|
1209
|
-
]
|
|
1210
|
-
}
|
|
1211
|
-
},
|
|
1212
|
-
{
|
|
1213
|
-
method: 'GET',
|
|
1214
|
-
path: '/v:major(\\d+).:minor(\\d+).:patch(\\d+)',
|
|
1215
|
-
handler: 'documentation.index',
|
|
1216
|
-
config: {
|
|
1217
|
-
auth: false,
|
|
1218
|
-
middlewares: [
|
|
1219
|
-
restrictAccess
|
|
1220
|
-
]
|
|
1221
|
-
}
|
|
1222
|
-
},
|
|
1223
|
-
{
|
|
1224
|
-
method: 'GET',
|
|
1225
|
-
path: '/login',
|
|
1226
|
-
handler: 'documentation.loginView',
|
|
1227
|
-
config: {
|
|
1228
|
-
auth: false
|
|
1229
|
-
}
|
|
1230
|
-
},
|
|
1231
|
-
{
|
|
1232
|
-
method: 'POST',
|
|
1233
|
-
path: '/login',
|
|
1234
|
-
handler: 'documentation.login',
|
|
1235
|
-
config: {
|
|
1236
|
-
auth: false
|
|
1237
|
-
}
|
|
1238
|
-
},
|
|
1239
|
-
{
|
|
1240
|
-
method: 'GET',
|
|
1241
|
-
path: '/getInfos',
|
|
1242
|
-
handler: 'documentation.getInfos',
|
|
1243
|
-
config: {
|
|
1244
|
-
policies: [
|
|
1245
|
-
{
|
|
1246
|
-
name: 'admin::hasPermissions',
|
|
1247
|
-
config: {
|
|
1248
|
-
actions: [
|
|
1249
|
-
'plugin::documentation.read'
|
|
1250
|
-
]
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
]
|
|
1254
|
-
}
|
|
1255
|
-
},
|
|
1256
|
-
{
|
|
1257
|
-
method: 'POST',
|
|
1258
|
-
path: '/regenerateDoc',
|
|
1259
|
-
handler: 'documentation.regenerateDoc',
|
|
1260
|
-
config: {
|
|
1261
|
-
policies: [
|
|
1262
|
-
{
|
|
1263
|
-
name: 'admin::hasPermissions',
|
|
1264
|
-
config: {
|
|
1265
|
-
actions: [
|
|
1266
|
-
'plugin::documentation.settings.regenerate'
|
|
1267
|
-
]
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
]
|
|
1271
|
-
}
|
|
1272
|
-
},
|
|
1273
|
-
{
|
|
1274
|
-
method: 'PUT',
|
|
1275
|
-
path: '/updateSettings',
|
|
1276
|
-
handler: 'documentation.updateSettings',
|
|
1277
|
-
config: {
|
|
1278
|
-
policies: [
|
|
1279
|
-
{
|
|
1280
|
-
name: 'admin::hasPermissions',
|
|
1281
|
-
config: {
|
|
1282
|
-
actions: [
|
|
1283
|
-
'plugin::documentation.settings.update'
|
|
1284
|
-
]
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
]
|
|
1288
|
-
}
|
|
1289
|
-
},
|
|
1290
|
-
{
|
|
1291
|
-
method: 'DELETE',
|
|
1292
|
-
path: '/deleteDoc/:version',
|
|
1293
|
-
handler: 'documentation.deleteDoc',
|
|
1294
|
-
config: {
|
|
1295
|
-
policies: []
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
];
|
|
1299
|
-
|
|
1300
|
-
const validation = {
|
|
1301
|
-
validateSettings: validateYupSchema(yup.object().shape({
|
|
1302
|
-
restrictedAccess: yup.boolean(),
|
|
1303
|
-
password: yup.string().min(8).matches(/[a-z]/, '${path} must contain at least one lowercase character').matches(/[A-Z]/, '${path} must contain at least one uppercase character').matches(/\d/, '${path} must contain at least one number').when('restrictedAccess', (value, initSchema)=>{
|
|
1304
|
-
return value ? initSchema.required('password is required') : initSchema;
|
|
1305
|
-
})
|
|
1306
|
-
}))
|
|
1307
|
-
};
|
|
1308
|
-
var documentation = {
|
|
1309
|
-
async getInfos (ctx) {
|
|
1310
|
-
try {
|
|
1311
|
-
const docService = getService('documentation');
|
|
1312
|
-
const docVersions = docService.getDocumentationVersions();
|
|
1313
|
-
const documentationAccess = await docService.getDocumentationAccess();
|
|
1314
|
-
ctx.send({
|
|
1315
|
-
docVersions,
|
|
1316
|
-
currentVersion: docService.getDocumentationVersion(),
|
|
1317
|
-
prefix: '/documentation',
|
|
1318
|
-
documentationAccess
|
|
1319
|
-
});
|
|
1320
|
-
} catch (err) {
|
|
1321
|
-
strapi.log.error(err);
|
|
1322
|
-
ctx.badRequest();
|
|
1323
|
-
}
|
|
1324
|
-
},
|
|
1325
|
-
async index (ctx, next) {
|
|
1326
|
-
try {
|
|
1327
|
-
/**
|
|
1328
|
-
* We don't expose the specs using koa-static or something else due to security reasons.
|
|
1329
|
-
* That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI.
|
|
1330
|
-
*/ const { major, minor, patch } = ctx.params;
|
|
1331
|
-
const version = major && minor && patch ? `${major}.${minor}.${patch}` : getService('documentation').getDocumentationVersion();
|
|
1332
|
-
const openAPISpecsPath = path.join(strapi.dirs.app.extensions, 'documentation', 'documentation', version, 'full_documentation.json');
|
|
1333
|
-
try {
|
|
1334
|
-
const documentation = fs.readFileSync(openAPISpecsPath, 'utf8');
|
|
1335
|
-
const layout = (await import('./chunks/index-Dz3orHaf.mjs')).default;
|
|
1336
|
-
const filledLayout = _.template(layout)({
|
|
1337
|
-
backendUrl: strapi.config.server.url,
|
|
1338
|
-
spec: JSON.stringify(JSON.parse(documentation))
|
|
1339
|
-
});
|
|
1340
|
-
try {
|
|
1341
|
-
const layoutPath = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public', 'index.html');
|
|
1342
|
-
await fs.ensureFile(layoutPath);
|
|
1343
|
-
await fs.writeFile(layoutPath, filledLayout);
|
|
1344
|
-
// Serve the file.
|
|
1345
|
-
ctx.url = path.basename(`${ctx.url}/index.html`);
|
|
1346
|
-
try {
|
|
1347
|
-
const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');
|
|
1348
|
-
return koaStatic(staticFolder)(ctx, next);
|
|
1349
|
-
} catch (e) {
|
|
1350
|
-
strapi.log.error(e);
|
|
1351
|
-
}
|
|
1352
|
-
} catch (e) {
|
|
1353
|
-
strapi.log.error(e);
|
|
1354
|
-
}
|
|
1355
|
-
} catch (e) {
|
|
1356
|
-
strapi.log.error(e);
|
|
1357
|
-
}
|
|
1358
|
-
} catch (e) {
|
|
1359
|
-
strapi.log.error(e);
|
|
1360
|
-
}
|
|
1361
|
-
},
|
|
1362
|
-
async loginView (ctx, next) {
|
|
1363
|
-
// lazy require cheerio
|
|
1364
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1365
|
-
const cheerio = require('cheerio');
|
|
1366
|
-
const { error } = ctx.query;
|
|
1367
|
-
try {
|
|
1368
|
-
const layout = (await import('./chunks/login-CYdORE5u.mjs')).default;
|
|
1369
|
-
const filledLayout = _.template(layout.toString())({
|
|
1370
|
-
actionUrl: `${strapi.config.server.url}/documentation/login`
|
|
1371
|
-
});
|
|
1372
|
-
const $ = cheerio.load(filledLayout);
|
|
1373
|
-
$('.error').text(_.isEmpty(error) ? '' : 'Wrong password...');
|
|
1374
|
-
try {
|
|
1375
|
-
const layoutPath = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public', 'login.html');
|
|
1376
|
-
await fs.ensureFile(layoutPath);
|
|
1377
|
-
await fs.writeFile(layoutPath, $.html());
|
|
1378
|
-
ctx.url = path.basename(`${ctx.url}/login.html`);
|
|
1379
|
-
try {
|
|
1380
|
-
const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');
|
|
1381
|
-
return koaStatic(staticFolder)(ctx, next);
|
|
1382
|
-
} catch (e) {
|
|
1383
|
-
strapi.log.error(e);
|
|
1384
|
-
}
|
|
1385
|
-
} catch (e) {
|
|
1386
|
-
strapi.log.error(e);
|
|
1387
|
-
}
|
|
1388
|
-
} catch (e) {
|
|
1389
|
-
strapi.log.error(e);
|
|
1390
|
-
}
|
|
1391
|
-
},
|
|
1392
|
-
async login (ctx) {
|
|
1393
|
-
const { body: { password } } = ctx.request;
|
|
1394
|
-
const { password: hash } = await strapi.store({
|
|
1395
|
-
type: 'plugin',
|
|
1396
|
-
name: 'documentation',
|
|
1397
|
-
key: 'config'
|
|
1398
|
-
}).get();
|
|
1399
|
-
const isValid = await bcrypt.compare(password, hash);
|
|
1400
|
-
let querystring = '?error=password';
|
|
1401
|
-
if (isValid && ctx.session) {
|
|
1402
|
-
ctx.session.documentation = {
|
|
1403
|
-
logged: true
|
|
1404
|
-
};
|
|
1405
|
-
querystring = '';
|
|
1406
|
-
}
|
|
1407
|
-
ctx.redirect(`${strapi.config.server.url}/documentation${querystring}`);
|
|
1408
|
-
},
|
|
1409
|
-
async regenerateDoc (ctx) {
|
|
1410
|
-
const { version } = ctx.request.body;
|
|
1411
|
-
const service = getService('documentation');
|
|
1412
|
-
const documentationVersions = service.getDocumentationVersions().map((el)=>el.version);
|
|
1413
|
-
if (_.isEmpty(version)) {
|
|
1414
|
-
return ctx.badRequest('Please provide a version.');
|
|
1415
|
-
}
|
|
1416
|
-
if (!documentationVersions.includes(version)) {
|
|
1417
|
-
return ctx.badRequest('The version you are trying to generate does not exist.');
|
|
1418
|
-
}
|
|
1419
|
-
try {
|
|
1420
|
-
strapi.reload.isWatching = false;
|
|
1421
|
-
await service.generateFullDoc(version);
|
|
1422
|
-
ctx.send({
|
|
1423
|
-
ok: true
|
|
1424
|
-
});
|
|
1425
|
-
} finally{
|
|
1426
|
-
strapi.reload.isWatching = true;
|
|
1427
|
-
}
|
|
1428
|
-
},
|
|
1429
|
-
async deleteDoc (ctx) {
|
|
1430
|
-
const { version } = ctx.params;
|
|
1431
|
-
const service = getService('documentation');
|
|
1432
|
-
const documentationVersions = service.getDocumentationVersions().map((el)=>el.version);
|
|
1433
|
-
if (_.isEmpty(version)) {
|
|
1434
|
-
return ctx.badRequest('Please provide a version.');
|
|
1435
|
-
}
|
|
1436
|
-
if (!documentationVersions.includes(version)) {
|
|
1437
|
-
return ctx.badRequest('The version you are trying to delete does not exist.');
|
|
1438
|
-
}
|
|
1439
|
-
try {
|
|
1440
|
-
strapi.reload.isWatching = false;
|
|
1441
|
-
await service.deleteDocumentation(version);
|
|
1442
|
-
ctx.send({
|
|
1443
|
-
ok: true
|
|
1444
|
-
});
|
|
1445
|
-
} finally{
|
|
1446
|
-
strapi.reload.isWatching = true;
|
|
1447
|
-
}
|
|
1448
|
-
},
|
|
1449
|
-
async updateSettings (ctx) {
|
|
1450
|
-
const pluginStore = strapi.store({
|
|
1451
|
-
type: 'plugin',
|
|
1452
|
-
name: 'documentation'
|
|
1453
|
-
});
|
|
1454
|
-
const data = await validation.validateSettings(ctx.request.body);
|
|
1455
|
-
const config = {
|
|
1456
|
-
restrictedAccess: Boolean(data.restrictedAccess)
|
|
1457
|
-
};
|
|
1458
|
-
if (data.password) {
|
|
1459
|
-
config.password = await bcrypt.hash(data.password, 10);
|
|
1460
|
-
}
|
|
1461
|
-
await pluginStore.set({
|
|
1462
|
-
key: 'config',
|
|
1463
|
-
value: config
|
|
1464
|
-
});
|
|
1465
|
-
return ctx.send({
|
|
1466
|
-
ok: true
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
|
|
1471
|
-
var controllers = {
|
|
1472
|
-
documentation
|
|
1473
|
-
};
|
|
1474
|
-
|
|
1475
|
-
const defaultConfig = {
|
|
1476
|
-
openapi: '3.0.0',
|
|
1477
|
-
info: {
|
|
1478
|
-
version: '1.0.0',
|
|
1479
|
-
title: 'DOCUMENTATION',
|
|
1480
|
-
description: '',
|
|
1481
|
-
termsOfService: 'YOUR_TERMS_OF_SERVICE_URL',
|
|
1482
|
-
contact: {
|
|
1483
|
-
name: 'TEAM',
|
|
1484
|
-
email: 'contact-email@something.io',
|
|
1485
|
-
url: 'mywebsite.io'
|
|
1486
|
-
},
|
|
1487
|
-
license: {
|
|
1488
|
-
name: 'Apache 2.0',
|
|
1489
|
-
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
|
|
1490
|
-
}
|
|
1491
|
-
},
|
|
1492
|
-
'x-strapi-config': {
|
|
1493
|
-
plugins: null,
|
|
1494
|
-
mutateDocumentation: null
|
|
1495
|
-
},
|
|
1496
|
-
servers: [],
|
|
1497
|
-
externalDocs: {
|
|
1498
|
-
description: 'Find out more',
|
|
1499
|
-
url: 'https://docs.strapi.io/developer-docs/latest/getting-started/introduction.html'
|
|
1500
|
-
},
|
|
1501
|
-
security: [
|
|
1502
|
-
{
|
|
1503
|
-
bearerAuth: []
|
|
1504
|
-
}
|
|
1505
|
-
],
|
|
1506
|
-
paths: {},
|
|
1507
|
-
components: {
|
|
1508
|
-
securitySchemes: {
|
|
1509
|
-
bearerAuth: {
|
|
1510
|
-
type: 'http',
|
|
1511
|
-
scheme: 'bearer',
|
|
1512
|
-
bearerFormat: 'JWT'
|
|
1513
|
-
}
|
|
1514
|
-
},
|
|
1515
|
-
schemas: {
|
|
1516
|
-
Error: {
|
|
1517
|
-
type: 'object',
|
|
1518
|
-
required: [
|
|
1519
|
-
'error'
|
|
1520
|
-
],
|
|
1521
|
-
properties: {
|
|
1522
|
-
data: {
|
|
1523
|
-
nullable: true,
|
|
1524
|
-
oneOf: [
|
|
1525
|
-
{
|
|
1526
|
-
type: 'object'
|
|
1527
|
-
},
|
|
1528
|
-
{
|
|
1529
|
-
type: 'array',
|
|
1530
|
-
items: {
|
|
1531
|
-
type: 'object'
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
]
|
|
1535
|
-
},
|
|
1536
|
-
error: {
|
|
1537
|
-
type: 'object',
|
|
1538
|
-
properties: {
|
|
1539
|
-
status: {
|
|
1540
|
-
type: 'integer'
|
|
1541
|
-
},
|
|
1542
|
-
name: {
|
|
1543
|
-
type: 'string'
|
|
1544
|
-
},
|
|
1545
|
-
message: {
|
|
1546
|
-
type: 'string'
|
|
1547
|
-
},
|
|
1548
|
-
details: {
|
|
1549
|
-
type: 'object'
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
|
|
1559
|
-
const config = {
|
|
1560
|
-
default: defaultConfig
|
|
1561
|
-
};
|
|
1
|
+
import { bootstrap } from './bootstrap.mjs';
|
|
2
|
+
import { register } from './register.mjs';
|
|
3
|
+
import services from './services/index.mjs';
|
|
4
|
+
import routes from './routes/index.mjs';
|
|
5
|
+
import controllers from './controllers/index.mjs';
|
|
6
|
+
import { config } from './config/index.mjs';
|
|
1562
7
|
|
|
1563
8
|
var index = {
|
|
1564
9
|
bootstrap,
|