@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
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
var pathToRegexp = require('path-to-regexp');
|
|
5
|
+
var pascalCase = require('./utils/pascal-case.js');
|
|
6
|
+
var queryParams = require('./utils/query-params.js');
|
|
7
|
+
var loopContentTypeNames = require('./utils/loop-content-type-names.js');
|
|
8
|
+
var getApiResponses = require('./utils/get-api-responses.js');
|
|
9
|
+
var routes = require('./utils/routes.js');
|
|
10
|
+
|
|
11
|
+
function _interopNamespaceDefault(e) {
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var pathToRegexp__namespace = /*#__PURE__*/_interopNamespaceDefault(pathToRegexp);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @description Parses a route with ':variable'
|
|
32
|
+
*
|
|
33
|
+
* @param {string} routePath - The route's path property
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/ const parsePathWithVariables = (routePath)=>{
|
|
36
|
+
const { tokens } = pathToRegexp__namespace.parse(routePath);
|
|
37
|
+
return tokens.map((token)=>{
|
|
38
|
+
switch(token.type){
|
|
39
|
+
case 'text':
|
|
40
|
+
return token.value;
|
|
41
|
+
case 'param':
|
|
42
|
+
return `{${token.name}}`;
|
|
43
|
+
case 'wildcard':
|
|
44
|
+
return `{${token.name}}`;
|
|
45
|
+
case 'group':
|
|
46
|
+
// Handle group tokens by mapping them within the same function context
|
|
47
|
+
return `(${parsePathWithVariables(token.tokens.map((t)=>t).join(''))})`;
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`Unknown token type: ${token.type}`);
|
|
50
|
+
}
|
|
51
|
+
}).join('');
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* @description Builds the required object for a path parameter
|
|
55
|
+
*
|
|
56
|
+
* @param {string} routePath - The route's path property
|
|
57
|
+
*
|
|
58
|
+
* @returns {object } Swagger path params object
|
|
59
|
+
*/ const getPathParams = (routePath)=>{
|
|
60
|
+
const { tokens } = pathToRegexp__namespace.parse(routePath);
|
|
61
|
+
return tokens.reduce((acc, param)=>{
|
|
62
|
+
// Skip non-parameter tokens
|
|
63
|
+
if (param.type !== 'param') {
|
|
64
|
+
return acc;
|
|
65
|
+
}
|
|
66
|
+
acc.push({
|
|
67
|
+
name: `${param.name}`,
|
|
68
|
+
in: 'path',
|
|
69
|
+
description: '',
|
|
70
|
+
deprecated: false,
|
|
71
|
+
required: true,
|
|
72
|
+
schema: {
|
|
73
|
+
type: 'number'
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return acc;
|
|
77
|
+
}, []);
|
|
78
|
+
};
|
|
79
|
+
const getPathWithPrefix = (prefix, route)=>{
|
|
80
|
+
// When the prefix is set on the routes and
|
|
81
|
+
// the current route is not trying to remove it
|
|
82
|
+
if (prefix && !_.has(route.config, 'prefix')) {
|
|
83
|
+
// Add the prefix to the path
|
|
84
|
+
return prefix.concat(route.path);
|
|
85
|
+
}
|
|
86
|
+
// Otherwise just return path
|
|
87
|
+
return route.path;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* @description Gets all paths based on routes
|
|
91
|
+
*
|
|
92
|
+
* @param {object} apiInfo
|
|
93
|
+
* @property {object} apiInfo.routeInfo - The api routes object
|
|
94
|
+
* @property {string} apiInfo.uniqueName - Content type name | Api name + Content type name
|
|
95
|
+
* @property {object} apiInfo.contentTypeInfo - The info object found on content type schemas
|
|
96
|
+
*
|
|
97
|
+
* @returns {object}
|
|
98
|
+
*/ const getPaths = ({ routeInfo, uniqueName, contentTypeInfo, kind })=>{
|
|
99
|
+
// Get the routes for the current content type
|
|
100
|
+
const contentTypeRoutes = routeInfo.routes.filter((route)=>{
|
|
101
|
+
return route.path.includes(contentTypeInfo.pluralName) || route.path.includes(contentTypeInfo.singularName);
|
|
102
|
+
});
|
|
103
|
+
const paths = contentTypeRoutes.reduce((acc, route)=>{
|
|
104
|
+
// TODO: Find a more reliable way to determine list of entities vs a single entity
|
|
105
|
+
const isListOfEntities = routes.hasFindMethod(route.handler);
|
|
106
|
+
const methodVerb = route.method.toLowerCase();
|
|
107
|
+
const hasPathParams = route.path.includes('/:');
|
|
108
|
+
const pathWithPrefix = getPathWithPrefix(routeInfo.prefix, route);
|
|
109
|
+
const routePath = hasPathParams ? parsePathWithVariables(pathWithPrefix) : pathWithPrefix;
|
|
110
|
+
const responses = getApiResponses({
|
|
111
|
+
uniqueName,
|
|
112
|
+
route,
|
|
113
|
+
isListOfEntities: kind !== 'singleType' && isListOfEntities
|
|
114
|
+
});
|
|
115
|
+
const swaggerConfig = {
|
|
116
|
+
responses,
|
|
117
|
+
tags: [
|
|
118
|
+
_.upperFirst(uniqueName)
|
|
119
|
+
],
|
|
120
|
+
parameters: [],
|
|
121
|
+
operationId: `${methodVerb}${routePath}`
|
|
122
|
+
};
|
|
123
|
+
if (isListOfEntities) {
|
|
124
|
+
swaggerConfig.parameters?.push(...queryParams);
|
|
125
|
+
}
|
|
126
|
+
if (hasPathParams) {
|
|
127
|
+
const pathParams = getPathParams(route.path);
|
|
128
|
+
swaggerConfig.parameters?.push(...pathParams);
|
|
129
|
+
}
|
|
130
|
+
if ([
|
|
131
|
+
'post',
|
|
132
|
+
'put'
|
|
133
|
+
].includes(methodVerb)) {
|
|
134
|
+
const refName = 'Request';
|
|
135
|
+
const requestBody = {
|
|
136
|
+
required: true,
|
|
137
|
+
content: {
|
|
138
|
+
'application/json': {
|
|
139
|
+
schema: {
|
|
140
|
+
$ref: `#/components/schemas/${pascalCase(uniqueName)}${refName}`
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
swaggerConfig.requestBody = requestBody;
|
|
146
|
+
}
|
|
147
|
+
_.set(acc, `${routePath}.${methodVerb}`, swaggerConfig);
|
|
148
|
+
return acc;
|
|
149
|
+
}, {});
|
|
150
|
+
return paths;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* @description - Builds the Swagger paths object for each api
|
|
154
|
+
*/ const buildApiEndpointPath = (api)=>{
|
|
155
|
+
// A reusable loop for building paths and component schemas
|
|
156
|
+
// Uses the api param to build a new set of params for each content type
|
|
157
|
+
// Passes these new params to the function provided
|
|
158
|
+
return loopContentTypeNames(api, getPaths);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
module.exports = buildApiEndpointPath;
|
|
162
|
+
//# sourceMappingURL=build-api-endpoint-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-api-endpoint-path.js","sources":["../../../../server/src/services/helpers/build-api-endpoint-path.ts"],"sourcesContent":["import _ from 'lodash';\nimport * as pathToRegexp from 'path-to-regexp';\n\nimport type { Core } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport pascalCase from './utils/pascal-case';\nimport queryParams from './utils/query-params';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport getApiResponses from './utils/get-api-responses';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\n/**\n * @description Parses a route with ':variable'\n *\n * @param {string} routePath - The route's path property\n * @returns {string}\n */\nconst parsePathWithVariables = (routePath: string): string => {\n const { tokens } = pathToRegexp.parse(routePath);\n\n return tokens\n .map((token) => {\n switch (token.type) {\n case 'text':\n return token.value;\n case 'param':\n return `{${token.name}}`;\n case 'wildcard':\n return `{${token.name}}`;\n case 'group':\n // Handle group tokens by mapping them within the same function context\n return `(${parsePathWithVariables(token.tokens.map((t) => t satisfies pathToRegexp.Token).join(''))})`;\n default:\n throw new Error(`Unknown token type: ${(token as any).type}`);\n }\n })\n .join('');\n};\n\n/**\n * @description Builds the required object for a path parameter\n *\n * @param {string} routePath - The route's path property\n *\n * @returns {object } Swagger path params object\n */\nconst getPathParams = (routePath: string): OpenAPIV3.ParameterObject[] => {\n const { tokens } = pathToRegexp.parse(routePath);\n\n return tokens.reduce((acc, param) => {\n // Skip non-parameter tokens\n if (param.type !== 'param') {\n return acc;\n }\n\n acc.push({\n name: `${param.name}`,\n in: 'path',\n description: '',\n deprecated: false,\n required: true,\n schema: { type: 'number' },\n });\n\n return acc;\n }, [] as OpenAPIV3.ParameterObject[]);\n};\n\nconst getPathWithPrefix = (prefix: string | undefined, route: Core.Route) => {\n // When the prefix is set on the routes and\n // the current route is not trying to remove it\n if (prefix && !_.has(route.config, 'prefix')) {\n // Add the prefix to the path\n return prefix.concat(route.path);\n }\n\n // Otherwise just return path\n return route.path;\n};\n\n/**\n * @description Gets all paths based on routes\n *\n * @param {object} apiInfo\n * @property {object} apiInfo.routeInfo - The api routes object\n * @property {string} apiInfo.uniqueName - Content type name | Api name + Content type name\n * @property {object} apiInfo.contentTypeInfo - The info object found on content type schemas\n *\n * @returns {object}\n */\nconst getPaths = ({ routeInfo, uniqueName, contentTypeInfo, kind }: ApiInfo) => {\n // Get the routes for the current content type\n const contentTypeRoutes = routeInfo.routes.filter((route) => {\n return (\n route.path.includes(contentTypeInfo.pluralName) ||\n route.path.includes(contentTypeInfo.singularName)\n );\n });\n\n const paths = contentTypeRoutes.reduce((acc: any, route: Core.Route) => {\n // TODO: Find a more reliable way to determine list of entities vs a single entity\n const isListOfEntities = hasFindMethod(route.handler);\n const methodVerb = route.method.toLowerCase();\n const hasPathParams = route.path.includes('/:');\n const pathWithPrefix = getPathWithPrefix(routeInfo.prefix, route);\n const routePath = hasPathParams ? parsePathWithVariables(pathWithPrefix) : pathWithPrefix;\n\n const responses = getApiResponses({\n uniqueName,\n route,\n isListOfEntities: kind !== 'singleType' && isListOfEntities,\n });\n\n const swaggerConfig: OpenAPIV3.OperationObject = {\n responses,\n tags: [_.upperFirst(uniqueName)],\n parameters: [],\n operationId: `${methodVerb}${routePath}`,\n };\n\n if (isListOfEntities) {\n swaggerConfig.parameters?.push(...queryParams);\n }\n\n if (hasPathParams) {\n const pathParams = getPathParams(route.path);\n swaggerConfig.parameters?.push(...pathParams);\n }\n\n if (['post', 'put'].includes(methodVerb)) {\n const refName = 'Request';\n const requestBody = {\n required: true,\n content: {\n 'application/json': {\n schema: {\n $ref: `#/components/schemas/${pascalCase(uniqueName)}${refName}`,\n },\n },\n },\n };\n\n swaggerConfig.requestBody = requestBody;\n }\n\n _.set(acc, `${routePath}.${methodVerb}`, swaggerConfig);\n\n return acc;\n }, {});\n\n return paths;\n};\n\n/**\n * @description - Builds the Swagger paths object for each api\n */\nconst buildApiEndpointPath = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getPaths);\n};\n\nexport default buildApiEndpointPath;\n"],"names":["parsePathWithVariables","routePath","tokens","pathToRegexp","parse","map","token","type","value","name","t","join","Error","getPathParams","reduce","acc","param","push","in","description","deprecated","required","schema","getPathWithPrefix","prefix","route","_","has","config","concat","path","getPaths","routeInfo","uniqueName","contentTypeInfo","kind","contentTypeRoutes","routes","filter","includes","pluralName","singularName","paths","isListOfEntities","hasFindMethod","handler","methodVerb","method","toLowerCase","hasPathParams","pathWithPrefix","responses","getApiResponses","swaggerConfig","tags","upperFirst","parameters","operationId","queryParams","pathParams","refName","requestBody","content","$ref","pascalCase","set","buildApiEndpointPath","api","loopContentTypeNames"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;IAMA,MAAMA,yBAAyB,CAACC,SAAAA,GAAAA;AAC9B,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAGC,uBAAAA,CAAaC,KAAK,CAACH,SAAAA,CAAAA;IAEtC,OAAOC,MAAAA,CACJG,GAAG,CAAC,CAACC,KAAAA,GAAAA;AACJ,QAAA,OAAQA,MAAMC,IAAI;YAChB,KAAK,MAAA;AACH,gBAAA,OAAOD,MAAME,KAAK;YACpB,KAAK,OAAA;AACH,gBAAA,OAAO,CAAC,CAAC,EAAEF,MAAMG,IAAI,CAAC,CAAC,CAAC;YAC1B,KAAK,UAAA;AACH,gBAAA,OAAO,CAAC,CAAC,EAAEH,MAAMG,IAAI,CAAC,CAAC,CAAC;YAC1B,KAAK,OAAA;;AAEH,gBAAA,OAAO,CAAC,CAAC,EAAET,sBAAuBM,CAAAA,KAAAA,CAAMJ,MAAM,CAACG,GAAG,CAAC,CAACK,IAAMA,CAAgCC,CAAAA,CAAAA,IAAI,CAAC,EAAA,CAAA,CAAA,CAAK,CAAC,CAAC;AACxG,YAAA;gBACE,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAE,KAACN,CAAcC,IAAI,CAAC,CAAC,CA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aAAe,EAAA;YACjB,MAAMU,UAAAA,GAAa9C,aAAcY,CAAAA,KAAAA,CAAMK,IAAI,CAAA;YAC3CuB,aAAcG,CAAAA,UAAU,EAAEvC,IAAQ0C,CAAAA,GAAAA,UAAAA,CAAAA;AACpC;QAEA,IAAI;AAAC,YAAA,MAAA;AAAQ,YAAA;SAAM,CAACpB,QAAQ,CAACO,UAAa,CAAA,EAAA;AACxC,YAAA,MAAMc,OAAU,GAAA,SAAA;AAChB,YAAA,MAAMC,WAAc,GAAA;gBAClBxC,QAAU,EAAA,IAAA;gBACVyC,OAAS,EAAA;oBACP,kBAAoB,EAAA;wBAClBxC,MAAQ,EAAA;AACNyC,4BAAAA,IAAAA,EAAM,CAAC,qBAAqB,EAAEC,WAAW/B,UAAY,CAAA,CAAA,EAAE2B,QAAQ;AACjE;AACF;AACF;AACF,aAAA;AAEAP,YAAAA,aAAAA,CAAcQ,WAAW,GAAGA,WAAAA;AAC9B;QAEAnC,CAAEuC,CAAAA,GAAG,CAAClD,GAAAA,EAAK,CAAC,EAAEd,UAAU,CAAC,EAAE6C,UAAW,CAAA,CAAC,EAAEO,aAAAA,CAAAA;QAEzC,OAAOtC,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;IAEJ,OAAO2B,KAAAA;AACT,CAAA;AAEA;;IAGA,MAAMwB,uBAAuB,CAACC,GAAAA,GAAAA;;;;AAI5B,IAAA,OAAOC,qBAAqBD,GAAKpC,EAAAA,QAAAA,CAAAA;AACnC;;;;"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import * as pathToRegexp from 'path-to-regexp';
|
|
3
|
+
import pascalCase from './utils/pascal-case.mjs';
|
|
4
|
+
import params from './utils/query-params.mjs';
|
|
5
|
+
import loopContentTypeNames from './utils/loop-content-type-names.mjs';
|
|
6
|
+
import getApiResponse from './utils/get-api-responses.mjs';
|
|
7
|
+
import { hasFindMethod } from './utils/routes.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description Parses a route with ':variable'
|
|
11
|
+
*
|
|
12
|
+
* @param {string} routePath - The route's path property
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/ const parsePathWithVariables = (routePath)=>{
|
|
15
|
+
const { tokens } = pathToRegexp.parse(routePath);
|
|
16
|
+
return tokens.map((token)=>{
|
|
17
|
+
switch(token.type){
|
|
18
|
+
case 'text':
|
|
19
|
+
return token.value;
|
|
20
|
+
case 'param':
|
|
21
|
+
return `{${token.name}}`;
|
|
22
|
+
case 'wildcard':
|
|
23
|
+
return `{${token.name}}`;
|
|
24
|
+
case 'group':
|
|
25
|
+
// Handle group tokens by mapping them within the same function context
|
|
26
|
+
return `(${parsePathWithVariables(token.tokens.map((t)=>t).join(''))})`;
|
|
27
|
+
default:
|
|
28
|
+
throw new Error(`Unknown token type: ${token.type}`);
|
|
29
|
+
}
|
|
30
|
+
}).join('');
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* @description Builds the required object for a path parameter
|
|
34
|
+
*
|
|
35
|
+
* @param {string} routePath - The route's path property
|
|
36
|
+
*
|
|
37
|
+
* @returns {object } Swagger path params object
|
|
38
|
+
*/ const getPathParams = (routePath)=>{
|
|
39
|
+
const { tokens } = pathToRegexp.parse(routePath);
|
|
40
|
+
return tokens.reduce((acc, param)=>{
|
|
41
|
+
// Skip non-parameter tokens
|
|
42
|
+
if (param.type !== 'param') {
|
|
43
|
+
return acc;
|
|
44
|
+
}
|
|
45
|
+
acc.push({
|
|
46
|
+
name: `${param.name}`,
|
|
47
|
+
in: 'path',
|
|
48
|
+
description: '',
|
|
49
|
+
deprecated: false,
|
|
50
|
+
required: true,
|
|
51
|
+
schema: {
|
|
52
|
+
type: 'number'
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return acc;
|
|
56
|
+
}, []);
|
|
57
|
+
};
|
|
58
|
+
const getPathWithPrefix = (prefix, route)=>{
|
|
59
|
+
// When the prefix is set on the routes and
|
|
60
|
+
// the current route is not trying to remove it
|
|
61
|
+
if (prefix && !_.has(route.config, 'prefix')) {
|
|
62
|
+
// Add the prefix to the path
|
|
63
|
+
return prefix.concat(route.path);
|
|
64
|
+
}
|
|
65
|
+
// Otherwise just return path
|
|
66
|
+
return route.path;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* @description Gets all paths based on routes
|
|
70
|
+
*
|
|
71
|
+
* @param {object} apiInfo
|
|
72
|
+
* @property {object} apiInfo.routeInfo - The api routes object
|
|
73
|
+
* @property {string} apiInfo.uniqueName - Content type name | Api name + Content type name
|
|
74
|
+
* @property {object} apiInfo.contentTypeInfo - The info object found on content type schemas
|
|
75
|
+
*
|
|
76
|
+
* @returns {object}
|
|
77
|
+
*/ const getPaths = ({ routeInfo, uniqueName, contentTypeInfo, kind })=>{
|
|
78
|
+
// Get the routes for the current content type
|
|
79
|
+
const contentTypeRoutes = routeInfo.routes.filter((route)=>{
|
|
80
|
+
return route.path.includes(contentTypeInfo.pluralName) || route.path.includes(contentTypeInfo.singularName);
|
|
81
|
+
});
|
|
82
|
+
const paths = contentTypeRoutes.reduce((acc, route)=>{
|
|
83
|
+
// TODO: Find a more reliable way to determine list of entities vs a single entity
|
|
84
|
+
const isListOfEntities = hasFindMethod(route.handler);
|
|
85
|
+
const methodVerb = route.method.toLowerCase();
|
|
86
|
+
const hasPathParams = route.path.includes('/:');
|
|
87
|
+
const pathWithPrefix = getPathWithPrefix(routeInfo.prefix, route);
|
|
88
|
+
const routePath = hasPathParams ? parsePathWithVariables(pathWithPrefix) : pathWithPrefix;
|
|
89
|
+
const responses = getApiResponse({
|
|
90
|
+
uniqueName,
|
|
91
|
+
route,
|
|
92
|
+
isListOfEntities: kind !== 'singleType' && isListOfEntities
|
|
93
|
+
});
|
|
94
|
+
const swaggerConfig = {
|
|
95
|
+
responses,
|
|
96
|
+
tags: [
|
|
97
|
+
_.upperFirst(uniqueName)
|
|
98
|
+
],
|
|
99
|
+
parameters: [],
|
|
100
|
+
operationId: `${methodVerb}${routePath}`
|
|
101
|
+
};
|
|
102
|
+
if (isListOfEntities) {
|
|
103
|
+
swaggerConfig.parameters?.push(...params);
|
|
104
|
+
}
|
|
105
|
+
if (hasPathParams) {
|
|
106
|
+
const pathParams = getPathParams(route.path);
|
|
107
|
+
swaggerConfig.parameters?.push(...pathParams);
|
|
108
|
+
}
|
|
109
|
+
if ([
|
|
110
|
+
'post',
|
|
111
|
+
'put'
|
|
112
|
+
].includes(methodVerb)) {
|
|
113
|
+
const refName = 'Request';
|
|
114
|
+
const requestBody = {
|
|
115
|
+
required: true,
|
|
116
|
+
content: {
|
|
117
|
+
'application/json': {
|
|
118
|
+
schema: {
|
|
119
|
+
$ref: `#/components/schemas/${pascalCase(uniqueName)}${refName}`
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
swaggerConfig.requestBody = requestBody;
|
|
125
|
+
}
|
|
126
|
+
_.set(acc, `${routePath}.${methodVerb}`, swaggerConfig);
|
|
127
|
+
return acc;
|
|
128
|
+
}, {});
|
|
129
|
+
return paths;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* @description - Builds the Swagger paths object for each api
|
|
133
|
+
*/ const buildApiEndpointPath = (api)=>{
|
|
134
|
+
// A reusable loop for building paths and component schemas
|
|
135
|
+
// Uses the api param to build a new set of params for each content type
|
|
136
|
+
// Passes these new params to the function provided
|
|
137
|
+
return loopContentTypeNames(api, getPaths);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export { buildApiEndpointPath as default };
|
|
141
|
+
//# sourceMappingURL=build-api-endpoint-path.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-api-endpoint-path.mjs","sources":["../../../../server/src/services/helpers/build-api-endpoint-path.ts"],"sourcesContent":["import _ from 'lodash';\nimport * as pathToRegexp from 'path-to-regexp';\n\nimport type { Core } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport pascalCase from './utils/pascal-case';\nimport queryParams from './utils/query-params';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport getApiResponses from './utils/get-api-responses';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\n/**\n * @description Parses a route with ':variable'\n *\n * @param {string} routePath - The route's path property\n * @returns {string}\n */\nconst parsePathWithVariables = (routePath: string): string => {\n const { tokens } = pathToRegexp.parse(routePath);\n\n return tokens\n .map((token) => {\n switch (token.type) {\n case 'text':\n return token.value;\n case 'param':\n return `{${token.name}}`;\n case 'wildcard':\n return `{${token.name}}`;\n case 'group':\n // Handle group tokens by mapping them within the same function context\n return `(${parsePathWithVariables(token.tokens.map((t) => t satisfies pathToRegexp.Token).join(''))})`;\n default:\n throw new Error(`Unknown token type: ${(token as any).type}`);\n }\n })\n .join('');\n};\n\n/**\n * @description Builds the required object for a path parameter\n *\n * @param {string} routePath - The route's path property\n *\n * @returns {object } Swagger path params object\n */\nconst getPathParams = (routePath: string): OpenAPIV3.ParameterObject[] => {\n const { tokens } = pathToRegexp.parse(routePath);\n\n return tokens.reduce((acc, param) => {\n // Skip non-parameter tokens\n if (param.type !== 'param') {\n return acc;\n }\n\n acc.push({\n name: `${param.name}`,\n in: 'path',\n description: '',\n deprecated: false,\n required: true,\n schema: { type: 'number' },\n });\n\n return acc;\n }, [] as OpenAPIV3.ParameterObject[]);\n};\n\nconst getPathWithPrefix = (prefix: string | undefined, route: Core.Route) => {\n // When the prefix is set on the routes and\n // the current route is not trying to remove it\n if (prefix && !_.has(route.config, 'prefix')) {\n // Add the prefix to the path\n return prefix.concat(route.path);\n }\n\n // Otherwise just return path\n return route.path;\n};\n\n/**\n * @description Gets all paths based on routes\n *\n * @param {object} apiInfo\n * @property {object} apiInfo.routeInfo - The api routes object\n * @property {string} apiInfo.uniqueName - Content type name | Api name + Content type name\n * @property {object} apiInfo.contentTypeInfo - The info object found on content type schemas\n *\n * @returns {object}\n */\nconst getPaths = ({ routeInfo, uniqueName, contentTypeInfo, kind }: ApiInfo) => {\n // Get the routes for the current content type\n const contentTypeRoutes = routeInfo.routes.filter((route) => {\n return (\n route.path.includes(contentTypeInfo.pluralName) ||\n route.path.includes(contentTypeInfo.singularName)\n );\n });\n\n const paths = contentTypeRoutes.reduce((acc: any, route: Core.Route) => {\n // TODO: Find a more reliable way to determine list of entities vs a single entity\n const isListOfEntities = hasFindMethod(route.handler);\n const methodVerb = route.method.toLowerCase();\n const hasPathParams = route.path.includes('/:');\n const pathWithPrefix = getPathWithPrefix(routeInfo.prefix, route);\n const routePath = hasPathParams ? parsePathWithVariables(pathWithPrefix) : pathWithPrefix;\n\n const responses = getApiResponses({\n uniqueName,\n route,\n isListOfEntities: kind !== 'singleType' && isListOfEntities,\n });\n\n const swaggerConfig: OpenAPIV3.OperationObject = {\n responses,\n tags: [_.upperFirst(uniqueName)],\n parameters: [],\n operationId: `${methodVerb}${routePath}`,\n };\n\n if (isListOfEntities) {\n swaggerConfig.parameters?.push(...queryParams);\n }\n\n if (hasPathParams) {\n const pathParams = getPathParams(route.path);\n swaggerConfig.parameters?.push(...pathParams);\n }\n\n if (['post', 'put'].includes(methodVerb)) {\n const refName = 'Request';\n const requestBody = {\n required: true,\n content: {\n 'application/json': {\n schema: {\n $ref: `#/components/schemas/${pascalCase(uniqueName)}${refName}`,\n },\n },\n },\n };\n\n swaggerConfig.requestBody = requestBody;\n }\n\n _.set(acc, `${routePath}.${methodVerb}`, swaggerConfig);\n\n return acc;\n }, {});\n\n return paths;\n};\n\n/**\n * @description - Builds the Swagger paths object for each api\n */\nconst buildApiEndpointPath = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getPaths);\n};\n\nexport default buildApiEndpointPath;\n"],"names":["parsePathWithVariables","routePath","tokens","pathToRegexp","parse","map","token","type","value","name","t","join","Error","getPathParams","reduce","acc","param","push","in","description","deprecated","required","schema","getPathWithPrefix","prefix","route","_","has","config","concat","path","getPaths","routeInfo","uniqueName","contentTypeInfo","kind","contentTypeRoutes","routes","filter","includes","pluralName","singularName","paths","isListOfEntities","hasFindMethod","handler","methodVerb","method","toLowerCase","hasPathParams","pathWithPrefix","responses","getApiResponses","swaggerConfig","tags","upperFirst","parameters","operationId","queryParams","pathParams","refName","requestBody","content","$ref","pascalCase","set","buildApiEndpointPath","api","loopContentTypeNames"],"mappings":";;;;;;;;AAcA;;;;;IAMA,MAAMA,yBAAyB,CAACC,SAAAA,GAAAA;AAC9B,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAGC,YAAAA,CAAaC,KAAK,CAACH,SAAAA,CAAAA;IAEtC,OAAOC,MAAAA,CACJG,GAAG,CAAC,CAACC,KAAAA,GAAAA;AACJ,QAAA,OAAQA,MAAMC,IAAI;YAChB,KAAK,MAAA;AACH,gBAAA,OAAOD,MAAME,KAAK;YACpB,KAAK,OAAA;AACH,gBAAA,OAAO,CAAC,CAAC,EAAEF,MAAMG,IAAI,CAAC,CAAC,CAAC;YAC1B,KAAK,UAAA;AACH,gBAAA,OAAO,CAAC,CAAC,EAAEH,MAAMG,IAAI,CAAC,CAAC,CAAC;YAC1B,KAAK,OAAA;;AAEH,gBAAA,OAAO,CAAC,CAAC,EAAET,sBAAuBM,CAAAA,KAAAA,CAAMJ,MAAM,CAACG,GAAG,CAAC,CAACK,IAAMA,CAAgCC,CAAAA,CAAAA,IAAI,CAAC,EAAA,CAAA,CAAA,CAAK,CAAC,CAAC;AACxG,YAAA;gBACE,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAE,KAACN,CAAcC,IAAI,CAAC,CAAC,CAAA;AAChE;AACF,KAAA,CAAA,CACCI,IAAI,CAAC,EAAA,CAAA;AACV,CAAA;AAEA;;;;;;IAOA,MAAME,gBAAgB,CAACZ,SAAAA,GAAAA;AACrB,IAAA,MAAM,EAAEC,MAAM,EAAE,GAAGC,YAAAA,CAAaC,KAAK,CAACH,SAAAA,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YAAA;SAAM,CAACpB,QAAQ,CAACO,UAAa,CAAA,EAAA;AACxC,YAAA,MAAMc,OAAU,GAAA,SAAA;AAChB,YAAA,MAAMC,WAAc,GAAA;gBAClBxC,QAAU,EAAA,IAAA;gBACVyC,OAAS,EAAA;oBACP,kBAAoB,EAAA;wBAClBxC,MAAQ,EAAA;AACNyC,4BAAAA,IAAAA,EAAM,CAAC,qBAAqB,EAAEC,WAAW/B,UAAY,CAAA,CAAA,EAAE2B,QAAQ;AACjE;AACF;AACF;AACF,aAAA;AAEAP,YAAAA,aAAAA,CAAcQ,WAAW,GAAGA,WAAAA;AAC9B;QAEAnC,CAAEuC,CAAAA,GAAG,CAAClD,GAAAA,EAAK,CAAC,EAAEd,UAAU,CAAC,EAAE6C,UAAW,CAAA,CAAC,EAAEO,aAAAA,CAAAA;QAEzC,OAAOtC,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;IAEJ,OAAO2B,KAAAA;AACT,CAAA;AAEA;;IAGA,MAAMwB,uBAAuB,CAACC,GAAAA,GAAAA;;;;AAI5B,IAAA,OAAOC,qBAAqBD,GAAKpC,EAAAA,QAAAA,CAAAA;AACnC;;;;"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
var cleanSchemaAttributes = require('./utils/clean-schema-attributes.js');
|
|
5
|
+
var loopContentTypeNames = require('./utils/loop-content-type-names.js');
|
|
6
|
+
var pascalCase = require('./utils/pascal-case.js');
|
|
7
|
+
var routes = require('./utils/routes.js');
|
|
8
|
+
|
|
9
|
+
const getRequiredAttributes = (allAttributes)=>{
|
|
10
|
+
const requiredAttributes = [];
|
|
11
|
+
for(const key in allAttributes){
|
|
12
|
+
if (allAttributes[key].required) {
|
|
13
|
+
requiredAttributes.push(key);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return requiredAttributes;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* @description Get all open api schema objects for a given content type
|
|
20
|
+
*
|
|
21
|
+
* @param {object} apiInfo
|
|
22
|
+
* @property {string} apiInfo.uniqueName - Api name | Api name + Content type name
|
|
23
|
+
* @property {object} apiInfo.attributes - Attributes on content type
|
|
24
|
+
* @property {object} apiInfo.routeInfo - The routes for the api
|
|
25
|
+
*
|
|
26
|
+
* @returns {object} Open API schemas
|
|
27
|
+
*/ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName })=>{
|
|
28
|
+
// Store response and request schemas in an object
|
|
29
|
+
let strapiComponentSchemas = {};
|
|
30
|
+
const schemas = {};
|
|
31
|
+
const typeName = pascalCase(uniqueName);
|
|
32
|
+
// adds a ComponentSchema to the Schemas so it can be used as Ref
|
|
33
|
+
const didAddStrapiComponentsToSchemas = (schemaName, schema)=>{
|
|
34
|
+
if (!Object.keys(schema) || !Object.keys(schema.properties)) return false;
|
|
35
|
+
// Add the Strapi components to the schema
|
|
36
|
+
strapiComponentSchemas = {
|
|
37
|
+
...strapiComponentSchemas,
|
|
38
|
+
[schemaName]: schema
|
|
39
|
+
};
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
// Get all the route methods
|
|
43
|
+
const routeMethods = routeInfo.routes.map((route)=>route.method);
|
|
44
|
+
const attributesToOmit = [
|
|
45
|
+
'createdAt',
|
|
46
|
+
'updatedAt',
|
|
47
|
+
'publishedAt',
|
|
48
|
+
'publishedBy',
|
|
49
|
+
'updatedBy',
|
|
50
|
+
'createdBy'
|
|
51
|
+
];
|
|
52
|
+
const attributesForRequest = _.omit(attributes, attributesToOmit);
|
|
53
|
+
// Get a list of required attribute names
|
|
54
|
+
const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);
|
|
55
|
+
// Build the request schemas when the route has POST or PUT methods
|
|
56
|
+
if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {
|
|
57
|
+
// Build localization requests schemas
|
|
58
|
+
// Build the request schema
|
|
59
|
+
Object.assign(schemas, {
|
|
60
|
+
[`${typeName}Request`]: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
required: [
|
|
63
|
+
'data'
|
|
64
|
+
],
|
|
65
|
+
properties: {
|
|
66
|
+
data: {
|
|
67
|
+
...requiredRequestAttributes.length && {
|
|
68
|
+
required: requiredRequestAttributes
|
|
69
|
+
},
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: cleanSchemaAttributes(attributesForRequest, {
|
|
72
|
+
isRequest: true,
|
|
73
|
+
didAddStrapiComponentsToSchemas
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// Check for routes that need to return a list
|
|
81
|
+
const hasListOfEntities = routeInfo.routes.filter((route)=>routes.hasFindMethod(route.handler)).length;
|
|
82
|
+
if (hasListOfEntities) {
|
|
83
|
+
// Build the list response schema
|
|
84
|
+
Object.assign(schemas, {
|
|
85
|
+
[`${typeName}ListResponse`]: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
data: {
|
|
89
|
+
type: 'array',
|
|
90
|
+
items: {
|
|
91
|
+
$ref: `#/components/schemas/${typeName}`
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
meta: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
pagination: {
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: {
|
|
100
|
+
page: {
|
|
101
|
+
type: 'integer'
|
|
102
|
+
},
|
|
103
|
+
pageSize: {
|
|
104
|
+
type: 'integer',
|
|
105
|
+
minimum: 25
|
|
106
|
+
},
|
|
107
|
+
pageCount: {
|
|
108
|
+
type: 'integer',
|
|
109
|
+
maximum: 1
|
|
110
|
+
},
|
|
111
|
+
total: {
|
|
112
|
+
type: 'integer'
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const requiredAttributes = getRequiredAttributes(attributes);
|
|
123
|
+
// Build the response schema
|
|
124
|
+
Object.assign(schemas, {
|
|
125
|
+
[`${typeName}`]: {
|
|
126
|
+
type: 'object',
|
|
127
|
+
...requiredAttributes.length && {
|
|
128
|
+
required: requiredAttributes
|
|
129
|
+
},
|
|
130
|
+
properties: {
|
|
131
|
+
id: {
|
|
132
|
+
type: 'number'
|
|
133
|
+
},
|
|
134
|
+
documentId: {
|
|
135
|
+
type: 'string'
|
|
136
|
+
},
|
|
137
|
+
...cleanSchemaAttributes(attributes, {
|
|
138
|
+
didAddStrapiComponentsToSchemas
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
[`${typeName}Response`]: {
|
|
143
|
+
type: 'object',
|
|
144
|
+
properties: {
|
|
145
|
+
data: {
|
|
146
|
+
$ref: `#/components/schemas/${typeName}`
|
|
147
|
+
},
|
|
148
|
+
meta: {
|
|
149
|
+
type: 'object'
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
...schemas,
|
|
156
|
+
...strapiComponentSchemas
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
const buildComponentSchema = (api)=>{
|
|
160
|
+
// A reusable loop for building paths and component schemas
|
|
161
|
+
// Uses the api param to build a new set of params for each content type
|
|
162
|
+
// Passes these new params to the function provided
|
|
163
|
+
return loopContentTypeNames(api, getAllSchemasForContentType);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
module.exports = buildComponentSchema;
|
|
167
|
+
//# sourceMappingURL=build-component-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-component-schema.js","sources":["../../../../server/src/services/helpers/build-component-schema.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { Core, Struct } from '@strapi/types';\n\nimport cleanSchemaAttributes from './utils/clean-schema-attributes';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport pascalCase from './utils/pascal-case';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\nconst getRequiredAttributes = (allAttributes: Struct.SchemaAttributes) => {\n const requiredAttributes: string[] = [];\n\n for (const key in allAttributes) {\n if (allAttributes[key].required) {\n requiredAttributes.push(key);\n }\n }\n\n return requiredAttributes;\n};\n\n/**\n * @description Get all open api schema objects for a given content type\n *\n * @param {object} apiInfo\n * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name\n * @property {object} apiInfo.attributes - Attributes on content type\n * @property {object} apiInfo.routeInfo - The routes for the api\n *\n * @returns {object} Open API schemas\n */\nconst getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }: ApiInfo) => {\n // Store response and request schemas in an object\n let strapiComponentSchemas = {};\n const schemas: OpenAPIV3.ComponentsObject = {};\n const typeName = pascalCase(uniqueName);\n\n // adds a ComponentSchema to the Schemas so it can be used as Ref\n const didAddStrapiComponentsToSchemas = (schemaName: string, schema: OpenAPIV3.SchemaObject) => {\n if (!Object.keys(schema) || !Object.keys(schema.properties!)) return false;\n\n // Add the Strapi components to the schema\n strapiComponentSchemas = {\n ...strapiComponentSchemas,\n [schemaName]: schema,\n };\n\n return true;\n };\n\n // Get all the route methods\n const routeMethods = routeInfo.routes.map((route: Core.Route) => route.method);\n\n const attributesToOmit = [\n 'createdAt',\n 'updatedAt',\n 'publishedAt',\n 'publishedBy',\n 'updatedBy',\n 'createdBy',\n ];\n\n const attributesForRequest = _.omit(attributes, attributesToOmit);\n // Get a list of required attribute names\n const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);\n // Build the request schemas when the route has POST or PUT methods\n if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {\n // Build localization requests schemas\n\n // Build the request schema\n Object.assign(schemas, {\n [`${typeName}Request`]: {\n type: 'object',\n required: ['data'],\n properties: {\n data: {\n ...(requiredRequestAttributes.length && { required: requiredRequestAttributes }),\n type: 'object',\n properties: cleanSchemaAttributes(attributesForRequest, {\n isRequest: true,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n },\n });\n }\n\n // Check for routes that need to return a list\n const hasListOfEntities = routeInfo.routes.filter((route: Core.Route) =>\n hasFindMethod(route.handler)\n ).length;\n\n if (hasListOfEntities) {\n // Build the list response schema\n Object.assign(schemas, {\n [`${typeName}ListResponse`]: {\n type: 'object',\n properties: {\n data: {\n type: 'array',\n items: {\n $ref: `#/components/schemas/${typeName}`,\n },\n },\n meta: {\n type: 'object',\n properties: {\n pagination: {\n type: 'object',\n properties: {\n page: { type: 'integer' },\n pageSize: { type: 'integer', minimum: 25 },\n pageCount: { type: 'integer', maximum: 1 },\n total: { type: 'integer' },\n },\n },\n },\n },\n },\n },\n });\n }\n\n const requiredAttributes = getRequiredAttributes(attributes);\n // Build the response schema\n Object.assign(schemas, {\n [`${typeName}`]: {\n type: 'object',\n ...(requiredAttributes.length && { required: requiredAttributes }),\n properties: {\n id: { type: 'number' },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, { didAddStrapiComponentsToSchemas }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst buildComponentSchema = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getAllSchemasForContentType);\n};\n\nexport default buildComponentSchema;\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","documentId","buildComponentSchema","api","loopContentTypeNames"],"mappings":";;;;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAe,CAAA;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAI,CAAA,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B;AACF;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,8BAA8B,CAAC,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,EAAW,GAAA;;AAEjF,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAWJ,CAAAA,UAAAA,CAAAA;;IAG5B,MAAMK,+BAAAA,GAAkC,CAACC,UAAoBC,EAAAA,MAAAA,GAAAA;AAC3D,QAAA,IAAI,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAW,CAAA,IAAA,CAACC,MAAOC,CAAAA,IAAI,CAACF,MAAAA,CAAOG,UAAU,CAAA,EAAI,OAAO,KAAA;;QAGrET,sBAAyB,GAAA;AACvB,YAAA,GAAGA,sBAAsB;AACzB,YAAA,CAACK,aAAaC;AAChB,SAAA;QAEA,OAAO,IAAA;AACT,KAAA;;IAGA,MAAMI,YAAAA,GAAeb,UAAUc,MAAM,CAACC,GAAG,CAAC,CAACC,KAAsBA,GAAAA,KAAAA,CAAMC,MAAM,CAAA;AAE7E,IAAA,MAAMC,gBAAmB,GAAA;AACvB,QAAA,WAAA;AACA,QAAA,WAAA;AACA,QAAA,aAAA;AACA,QAAA,aAAA;AACA,QAAA,WAAA;AACA,QAAA;AACD,KAAA;AAED,IAAA,MAAM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