@strapi/plugin-documentation 5.0.0-beta.0 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/_chunks/{index-D1KkfApT.js → App-Cmiagsr-.js} +93 -53
- package/dist/_chunks/App-Cmiagsr-.js.map +1 -0
- package/dist/_chunks/{index-7xstUX8_.mjs → App-pk6g9tYL.mjs} +69 -46
- package/dist/_chunks/App-pk6g9tYL.mjs.map +1 -0
- package/dist/_chunks/Settings-CqLmbMfv.mjs +223 -0
- package/dist/_chunks/Settings-CqLmbMfv.mjs.map +1 -0
- package/dist/_chunks/Settings-MmkmHoxg.js +243 -0
- package/dist/_chunks/Settings-MmkmHoxg.js.map +1 -0
- package/dist/_chunks/{ar-4yWQcJB-.js → ar-CkqTE6jh.js} +1 -1
- package/dist/_chunks/ar-CkqTE6jh.js.map +1 -0
- package/dist/_chunks/{ar-dlnabvQE.mjs → ar-ckp9T43y.mjs} +1 -1
- package/dist/_chunks/ar-ckp9T43y.mjs.map +1 -0
- package/dist/_chunks/{cs-knLCHelx.js → cs-BbyKo6Hc.js} +1 -1
- package/dist/_chunks/cs-BbyKo6Hc.js.map +1 -0
- package/dist/_chunks/{cs-x2Pr-Y38.mjs → cs-ciLYCxgd.mjs} +1 -1
- package/dist/_chunks/cs-ciLYCxgd.mjs.map +1 -0
- package/dist/_chunks/{de-D0HJjv1r.js → de-CHwC0A85.js} +1 -1
- package/dist/_chunks/de-CHwC0A85.js.map +1 -0
- package/dist/_chunks/{de-10J3uf4y.mjs → de-DqkAUMvP.mjs} +1 -1
- package/dist/_chunks/de-DqkAUMvP.mjs.map +1 -0
- package/dist/_chunks/{dk-_8JEfZdj.mjs → dk-DgCq8mF-.mjs} +1 -1
- package/dist/_chunks/dk-DgCq8mF-.mjs.map +1 -0
- package/dist/_chunks/{dk-OGCIxZ4f.js → dk-qlI2J6S0.js} +1 -1
- package/dist/_chunks/dk-qlI2J6S0.js.map +1 -0
- package/dist/_chunks/{en-YgFnjikD.js → en-Cfq2Inmo.js} +1 -1
- package/dist/_chunks/en-Cfq2Inmo.js.map +1 -0
- package/dist/_chunks/{en-V4ac9UMW.mjs → en-DfCC9sZn.mjs} +1 -1
- package/dist/_chunks/en-DfCC9sZn.mjs.map +1 -0
- package/dist/_chunks/{es-f_rfLY5r.mjs → es-CEiXVnsb.mjs} +1 -1
- package/dist/_chunks/es-CEiXVnsb.mjs.map +1 -0
- package/dist/_chunks/{es-5fRDaTSK.js → es-DH1GVZe7.js} +1 -1
- package/dist/_chunks/es-DH1GVZe7.js.map +1 -0
- package/dist/_chunks/{fr-qviymkcR.js → fr-B1x-Nj5w.js} +1 -1
- package/dist/_chunks/fr-B1x-Nj5w.js.map +1 -0
- package/dist/_chunks/{fr-L2xRpd2l.mjs → fr-BlX-v4UF.mjs} +1 -1
- package/dist/_chunks/fr-BlX-v4UF.mjs.map +1 -0
- package/dist/_chunks/getTrad-AjYeGjZg.mjs +51 -0
- package/dist/_chunks/getTrad-AjYeGjZg.mjs.map +1 -0
- package/dist/_chunks/getTrad-CPA7x4Cg.js +50 -0
- package/dist/_chunks/getTrad-CPA7x4Cg.js.map +1 -0
- package/dist/_chunks/{id-l-r-lPDE.mjs → id-CPOl6_EU.mjs} +1 -1
- package/dist/_chunks/id-CPOl6_EU.mjs.map +1 -0
- package/dist/_chunks/{id-caKGgafZ.js → id-D3yFE72d.js} +1 -1
- package/dist/_chunks/id-D3yFE72d.js.map +1 -0
- package/{server/public/index.html → dist/_chunks/index-BTFWrNiz.mjs} +9 -4
- package/dist/_chunks/index-BTFWrNiz.mjs.map +1 -0
- package/dist/_chunks/index-Bjeq6z8p.js +100 -0
- package/dist/_chunks/index-Bjeq6z8p.js.map +1 -0
- package/dist/_chunks/index-CEoG11hQ.mjs +101 -0
- package/dist/_chunks/index-CEoG11hQ.mjs.map +1 -0
- package/dist/_chunks/index-CYcTK1eg.js +75 -0
- package/dist/_chunks/index-CYcTK1eg.js.map +1 -0
- package/dist/_chunks/{it-nCSZoaet.mjs → it-DWJI563z.mjs} +1 -1
- package/dist/_chunks/it-DWJI563z.mjs.map +1 -0
- package/dist/_chunks/{it-e3T319Va.js → it-WuNBIqG8.js} +1 -1
- package/dist/_chunks/it-WuNBIqG8.js.map +1 -0
- package/dist/_chunks/{ko-pUwRxmfG.mjs → ko-CFzSHayG.mjs} +1 -1
- package/dist/_chunks/ko-CFzSHayG.mjs.map +1 -0
- package/dist/_chunks/{ko-nWCOH-TF.js → ko-De5iYa_O.js} +1 -1
- package/dist/_chunks/ko-De5iYa_O.js.map +1 -0
- package/dist/_chunks/login-EQSKn2h7.js +150 -0
- package/dist/_chunks/login-EQSKn2h7.js.map +1 -0
- package/{server/public/login.html → dist/_chunks/login-KS59cQ6U.mjs} +6 -1
- package/dist/_chunks/login-KS59cQ6U.mjs.map +1 -0
- package/dist/_chunks/{ms-8e8SEhhY.mjs → ms-CUgPFo4U.mjs} +1 -1
- package/dist/_chunks/ms-CUgPFo4U.mjs.map +1 -0
- package/dist/_chunks/{ms-CSGAOmvV.js → ms-DQfa3FDx.js} +1 -1
- package/dist/_chunks/ms-DQfa3FDx.js.map +1 -0
- package/dist/_chunks/{nl-82NK6g7v.js → nl-BZHlqphk.js} +1 -1
- package/dist/_chunks/nl-BZHlqphk.js.map +1 -0
- package/dist/_chunks/{nl-RjdbZWuM.mjs → nl-B_7CHwVD.mjs} +1 -1
- package/dist/_chunks/nl-B_7CHwVD.mjs.map +1 -0
- package/dist/_chunks/{pl-UMuW3iDh.js → pl-DDl5i_mP.js} +1 -1
- package/dist/_chunks/pl-DDl5i_mP.js.map +1 -0
- package/dist/_chunks/{pl-sh4sAKA8.mjs → pl-DwLr8sw9.mjs} +1 -1
- package/dist/_chunks/pl-DwLr8sw9.mjs.map +1 -0
- package/dist/_chunks/{pt-2sEtQifY.js → pt-4GQ8ermL.js} +1 -1
- package/dist/_chunks/pt-4GQ8ermL.js.map +1 -0
- package/dist/_chunks/{pt-BR-G0-nWgFV.js → pt-BR-D24CJ0qp.js} +1 -1
- package/dist/_chunks/pt-BR-D24CJ0qp.js.map +1 -0
- package/dist/_chunks/{pt-BR-uX3O_t0X.mjs → pt-BR-MVXc6V9P.mjs} +1 -1
- package/dist/_chunks/pt-BR-MVXc6V9P.mjs.map +1 -0
- package/dist/_chunks/{pt-GqKRRnNe.mjs → pt-C2N9fdeh.mjs} +1 -1
- package/dist/_chunks/pt-C2N9fdeh.mjs.map +1 -0
- package/dist/_chunks/{ru-dQr7xFOb.mjs → ru-BddeNlU0.mjs} +1 -1
- package/dist/_chunks/ru-BddeNlU0.mjs.map +1 -0
- package/dist/_chunks/{ru-wJyWus4I.js → ru-QwZYcU6K.js} +1 -1
- package/dist/_chunks/ru-QwZYcU6K.js.map +1 -0
- package/dist/_chunks/{sk-nreoyD6V.mjs → sk-BmT4uZTG.mjs} +1 -1
- package/dist/_chunks/sk-BmT4uZTG.mjs.map +1 -0
- package/dist/_chunks/{sk-mcEz1PMW.js → sk-DgAXilB1.js} +1 -1
- package/dist/_chunks/sk-DgAXilB1.js.map +1 -0
- package/dist/_chunks/{sv-V86KaP9y.js → sv-CCLcAo3U.js} +1 -1
- package/dist/_chunks/sv-CCLcAo3U.js.map +1 -0
- package/dist/_chunks/{sv-kIUD_46v.mjs → sv-D_-KBtcw.mjs} +1 -1
- package/dist/_chunks/sv-D_-KBtcw.mjs.map +1 -0
- package/dist/_chunks/{th-pZN4HdUY.js → th-BhgV1BbW.js} +1 -1
- package/dist/_chunks/th-BhgV1BbW.js.map +1 -0
- package/dist/_chunks/{th-IcmZ0Yif.mjs → th-DkuoSGii.mjs} +1 -1
- package/dist/_chunks/th-DkuoSGii.mjs.map +1 -0
- package/dist/_chunks/{tr-fCijT6nA.js → tr-BysnAErC.js} +1 -1
- package/dist/_chunks/tr-BysnAErC.js.map +1 -0
- package/dist/_chunks/{tr-CkXew0gQ.mjs → tr-l-xxK4Yk.mjs} +1 -1
- package/dist/_chunks/tr-l-xxK4Yk.mjs.map +1 -0
- package/dist/_chunks/{uk-TEHpQuls.js → uk-CNlbntFx.js} +1 -1
- package/dist/_chunks/uk-CNlbntFx.js.map +1 -0
- package/dist/_chunks/{uk-E8Js7gDb.mjs → uk-Cpmsxyku.mjs} +1 -1
- package/dist/_chunks/uk-Cpmsxyku.mjs.map +1 -0
- package/dist/_chunks/{vi-k1R3Y3mS.mjs → vi-ClWGrFm9.mjs} +1 -1
- package/dist/_chunks/vi-ClWGrFm9.mjs.map +1 -0
- package/dist/_chunks/{vi-Nxtm0xZz.js → vi-_ib0GmNl.js} +1 -1
- package/dist/_chunks/vi-_ib0GmNl.js.map +1 -0
- package/dist/_chunks/{zh-Vd3mfBR-.mjs → zh-Glkg1L2g.mjs} +1 -1
- package/dist/_chunks/zh-Glkg1L2g.mjs.map +1 -0
- package/dist/_chunks/{zh-Hans-tFSnVett.js → zh-Hans-L_5U2KqC.js} +1 -1
- package/dist/_chunks/zh-Hans-L_5U2KqC.js.map +1 -0
- package/dist/_chunks/{zh-Hans-FdUTcggu.mjs → zh-Hans-XLMwjASk.mjs} +1 -1
- package/dist/_chunks/zh-Hans-XLMwjASk.mjs.map +1 -0
- package/dist/_chunks/{zh-bgauBZz8.js → zh-aEZZdkOu.js} +1 -1
- package/dist/_chunks/zh-aEZZdkOu.js.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/SettingsForm.d.ts +8 -0
- package/dist/admin/src/constants.d.ts +18 -0
- package/dist/admin/src/index.d.ts +14 -0
- package/dist/admin/src/pages/App.d.ts +2 -0
- package/dist/admin/src/pages/Settings.d.ts +2 -0
- package/dist/admin/src/pluginId.d.ts +1 -0
- package/dist/admin/src/services/api.d.ts +13 -0
- package/dist/admin/src/types.d.ts +16 -0
- package/dist/admin/src/utils/baseQuery.d.ts +5 -0
- package/dist/admin/src/utils/getTrad.d.ts +1 -0
- package/dist/admin/src/utils/index.d.ts +2 -0
- package/dist/admin/src/utils/prefixPluginTranslations.d.ts +2 -0
- package/dist/server/index.js +1263 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +1238 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/src/bootstrap.d.ts +5 -0
- package/dist/server/src/bootstrap.d.ts.map +1 -0
- package/dist/server/src/config/default-plugin-config.d.ts +3 -0
- package/dist/server/src/config/default-plugin-config.d.ts.map +1 -0
- package/dist/server/src/config/index.d.ts +4 -0
- package/dist/server/src/config/index.d.ts.map +1 -0
- package/dist/server/src/controllers/documentation.d.ts +12 -0
- package/dist/server/src/controllers/documentation.d.ts.map +1 -0
- package/dist/server/src/controllers/index.d.ts +14 -0
- package/dist/server/src/controllers/index.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +91 -0
- package/dist/server/src/index.d.ts.map +1 -0
- package/dist/server/src/middlewares/documentation.d.ts +5 -0
- package/dist/server/src/middlewares/documentation.d.ts.map +1 -0
- package/dist/server/src/middlewares/restrict-access.d.ts +4 -0
- package/dist/server/src/middlewares/restrict-access.d.ts.map +1 -0
- package/dist/server/src/register.d.ts +5 -0
- package/dist/server/src/register.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts +36 -0
- package/dist/server/src/routes/index.d.ts.map +1 -0
- package/dist/server/src/services/__mocks__/mock-content-types.d.ts +449 -0
- package/dist/server/src/services/__mocks__/mock-content-types.d.ts.map +1 -0
- package/dist/server/src/services/__mocks__/mock-strapi-data.d.ts +592 -0
- package/dist/server/src/services/__mocks__/mock-strapi-data.d.ts.map +1 -0
- package/dist/server/src/services/documentation.d.ts +36 -0
- package/dist/server/src/services/documentation.d.ts.map +1 -0
- package/dist/server/src/services/helpers/build-api-endpoint-path.d.ts +7 -0
- package/dist/server/src/services/helpers/build-api-endpoint-path.d.ts.map +1 -0
- package/dist/server/src/services/helpers/build-component-schema.d.ts +4 -0
- package/dist/server/src/services/helpers/build-component-schema.d.ts.map +1 -0
- package/dist/server/src/services/helpers/index.d.ts +4 -0
- package/dist/server/src/services/helpers/index.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts +15 -0
- package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/get-api-responses.d.ts +15 -0
- package/dist/server/src/services/helpers/utils/get-api-responses.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/get-schema-data.d.ts +12 -0
- package/dist/server/src/services/helpers/utils/get-schema-data.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts +7 -0
- package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/pascal-case.d.ts +3 -0
- package/dist/server/src/services/helpers/utils/pascal-case.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/query-params.d.ts +4 -0
- package/dist/server/src/services/helpers/utils/query-params.d.ts.map +1 -0
- package/dist/server/src/services/helpers/utils/routes.d.ts +3 -0
- package/dist/server/src/services/helpers/utils/routes.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +43 -0
- package/dist/server/src/services/index.d.ts.map +1 -0
- package/dist/server/src/services/override.d.ts +21 -0
- package/dist/server/src/services/override.d.ts.map +1 -0
- package/dist/server/src/services/utils/get-plugins-that-need-documentation.d.ts +4 -0
- package/dist/server/src/services/utils/get-plugins-that-need-documentation.d.ts.map +1 -0
- package/dist/server/src/types.d.ts +28 -0
- package/dist/server/src/types.d.ts.map +1 -0
- package/dist/server/src/utils.d.ts +12 -0
- package/dist/server/src/utils.d.ts.map +1 -0
- package/package.json +45 -25
- package/strapi-server.js +1 -1
- package/.eslintignore +0 -1
- package/.eslintrc +0 -17
- package/admin/src/constants.js +0 -17
- package/admin/src/hooks/useDocumentation.js +0 -81
- package/admin/src/index.js +0 -62
- package/admin/src/pages/PluginPage/index.jsx +0 -212
- package/admin/src/pages/PluginPage/tests/index.test.jsx +0 -160
- package/admin/src/pages/SettingsPage/index.jsx +0 -202
- package/admin/src/pages/SettingsPage/tests/index.test.jsx +0 -72
- package/admin/src/pluginId.js +0 -5
- package/admin/src/translations/ar.json +0 -20
- package/admin/src/translations/cs.json +0 -21
- package/admin/src/translations/de.json +0 -26
- package/admin/src/translations/dk.json +0 -39
- package/admin/src/translations/en.json +0 -39
- package/admin/src/translations/es.json +0 -39
- package/admin/src/translations/fr.json +0 -26
- package/admin/src/translations/id.json +0 -24
- package/admin/src/translations/it.json +0 -26
- package/admin/src/translations/ko.json +0 -39
- package/admin/src/translations/ms.json +0 -23
- package/admin/src/translations/nl.json +0 -21
- package/admin/src/translations/pl.json +0 -39
- package/admin/src/translations/pt-BR.json +0 -21
- package/admin/src/translations/pt.json +0 -21
- package/admin/src/translations/ru.json +0 -39
- package/admin/src/translations/sk.json +0 -24
- package/admin/src/translations/sv.json +0 -39
- package/admin/src/translations/th.json +0 -24
- package/admin/src/translations/tr.json +0 -39
- package/admin/src/translations/uk.json +0 -23
- package/admin/src/translations/vi.json +0 -24
- package/admin/src/translations/zh-Hans.json +0 -28
- package/admin/src/translations/zh.json +0 -39
- package/admin/src/utils/getTrad.js +0 -5
- package/admin/src/utils/index.js +0 -2
- package/admin/src/utils/prefixPluginTranslations.js +0 -13
- package/dist/_chunks/ar-4yWQcJB-.js.map +0 -1
- package/dist/_chunks/ar-dlnabvQE.mjs.map +0 -1
- package/dist/_chunks/cs-knLCHelx.js.map +0 -1
- package/dist/_chunks/cs-x2Pr-Y38.mjs.map +0 -1
- package/dist/_chunks/de-10J3uf4y.mjs.map +0 -1
- package/dist/_chunks/de-D0HJjv1r.js.map +0 -1
- package/dist/_chunks/dk-OGCIxZ4f.js.map +0 -1
- package/dist/_chunks/dk-_8JEfZdj.mjs.map +0 -1
- package/dist/_chunks/en-V4ac9UMW.mjs.map +0 -1
- package/dist/_chunks/en-YgFnjikD.js.map +0 -1
- package/dist/_chunks/es-5fRDaTSK.js.map +0 -1
- package/dist/_chunks/es-f_rfLY5r.mjs.map +0 -1
- package/dist/_chunks/fr-L2xRpd2l.mjs.map +0 -1
- package/dist/_chunks/fr-qviymkcR.js.map +0 -1
- package/dist/_chunks/id-caKGgafZ.js.map +0 -1
- package/dist/_chunks/id-l-r-lPDE.mjs.map +0 -1
- package/dist/_chunks/index-7xstUX8_.mjs.map +0 -1
- package/dist/_chunks/index-D1KkfApT.js.map +0 -1
- package/dist/_chunks/index-NbPCucJl.js +0 -195
- package/dist/_chunks/index-NbPCucJl.js.map +0 -1
- package/dist/_chunks/index-NvJ4m2q5.mjs +0 -201
- package/dist/_chunks/index-NvJ4m2q5.mjs.map +0 -1
- package/dist/_chunks/index-VpLAJXMs.mjs +0 -174
- package/dist/_chunks/index-VpLAJXMs.mjs.map +0 -1
- package/dist/_chunks/index-r7HsQTou.js +0 -200
- package/dist/_chunks/index-r7HsQTou.js.map +0 -1
- package/dist/_chunks/it-e3T319Va.js.map +0 -1
- package/dist/_chunks/it-nCSZoaet.mjs.map +0 -1
- package/dist/_chunks/ko-nWCOH-TF.js.map +0 -1
- package/dist/_chunks/ko-pUwRxmfG.mjs.map +0 -1
- package/dist/_chunks/ms-8e8SEhhY.mjs.map +0 -1
- package/dist/_chunks/ms-CSGAOmvV.js.map +0 -1
- package/dist/_chunks/nl-82NK6g7v.js.map +0 -1
- package/dist/_chunks/nl-RjdbZWuM.mjs.map +0 -1
- package/dist/_chunks/pl-UMuW3iDh.js.map +0 -1
- package/dist/_chunks/pl-sh4sAKA8.mjs.map +0 -1
- package/dist/_chunks/pt-2sEtQifY.js.map +0 -1
- package/dist/_chunks/pt-BR-G0-nWgFV.js.map +0 -1
- package/dist/_chunks/pt-BR-uX3O_t0X.mjs.map +0 -1
- package/dist/_chunks/pt-GqKRRnNe.mjs.map +0 -1
- package/dist/_chunks/ru-dQr7xFOb.mjs.map +0 -1
- package/dist/_chunks/ru-wJyWus4I.js.map +0 -1
- package/dist/_chunks/sk-mcEz1PMW.js.map +0 -1
- package/dist/_chunks/sk-nreoyD6V.mjs.map +0 -1
- package/dist/_chunks/sv-V86KaP9y.js.map +0 -1
- package/dist/_chunks/sv-kIUD_46v.mjs.map +0 -1
- package/dist/_chunks/th-IcmZ0Yif.mjs.map +0 -1
- package/dist/_chunks/th-pZN4HdUY.js.map +0 -1
- package/dist/_chunks/tr-CkXew0gQ.mjs.map +0 -1
- package/dist/_chunks/tr-fCijT6nA.js.map +0 -1
- package/dist/_chunks/uk-E8Js7gDb.mjs.map +0 -1
- package/dist/_chunks/uk-TEHpQuls.js.map +0 -1
- package/dist/_chunks/useDocumentation-6Ks-_Ms6.mjs +0 -68
- package/dist/_chunks/useDocumentation-6Ks-_Ms6.mjs.map +0 -1
- package/dist/_chunks/useDocumentation-S0e4mU-U.js +0 -67
- package/dist/_chunks/useDocumentation-S0e4mU-U.js.map +0 -1
- package/dist/_chunks/vi-Nxtm0xZz.js.map +0 -1
- package/dist/_chunks/vi-k1R3Y3mS.mjs.map +0 -1
- package/dist/_chunks/zh-Hans-FdUTcggu.mjs.map +0 -1
- package/dist/_chunks/zh-Hans-tFSnVett.js.map +0 -1
- package/dist/_chunks/zh-Vd3mfBR-.mjs.map +0 -1
- package/dist/_chunks/zh-bgauBZz8.js.map +0 -1
- package/jest.config.front.js +0 -7
- package/jest.config.js +0 -6
- package/packup.config.ts +0 -22
- package/server/bootstrap.js +0 -54
- package/server/config/default-plugin-config.js +0 -35
- package/server/config/index.js +0 -7
- package/server/controllers/documentation.js +0 -241
- package/server/controllers/index.js +0 -7
- package/server/index.js +0 -17
- package/server/middlewares/documentation.js +0 -25
- package/server/middlewares/index.js +0 -7
- package/server/middlewares/restrict-access.js +0 -24
- package/server/register.js +0 -11
- package/server/routes/index.js +0 -84
- package/server/services/__mocks__/mock-content-types.js +0 -264
- package/server/services/__mocks__/mock-strapi-data.js +0 -183
- package/server/services/__tests__/build-component-schema.test.js +0 -761
- package/server/services/__tests__/documentation.test.js +0 -481
- package/server/services/__tests__/override.test.js +0 -85
- package/server/services/documentation.js +0 -246
- package/server/services/helpers/build-api-endpoint-path.js +0 -186
- package/server/services/helpers/build-component-schema.js +0 -254
- package/server/services/helpers/index.js +0 -9
- package/server/services/helpers/utils/clean-schema-attributes.js +0 -246
- package/server/services/helpers/utils/get-api-responses.js +0 -105
- package/server/services/helpers/utils/get-schema-data.js +0 -32
- package/server/services/helpers/utils/loop-content-type-names.js +0 -55
- package/server/services/helpers/utils/pascal-case.js +0 -9
- package/server/services/helpers/utils/query-params.js +0 -105
- package/server/services/helpers/utils/routes.js +0 -10
- package/server/services/index.js +0 -9
- package/server/services/override.js +0 -52
- package/server/services/utils/default-openapi-components.js +0 -40
- package/server/services/utils/get-plugins-that-need-documentation.js +0 -24
- package/tests/server.js +0 -37
- package/tests/setup.js +0 -15
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const 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;
|