@strapi/plugin-documentation 5.41.1 → 5.42.0

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 CHANGED
@@ -16,7 +16,7 @@ This plugin automates your API documentation creation. It basically generates a
16
16
 
17
17
  ### Config
18
18
 
19
- Create a `settings.json` file located in `src/extensions/documentation/config` folder where you can specify all your environment variables, licenses, external documentation and so one...
19
+ Create a `settings.json` file located in `src/extensions/documentation/config` folder where you can specify all your environment variables, licenses, external documentation and so on...
20
20
  You can add all the entries listed in the [specification](https://swagger.io/specification/).
21
21
 
22
22
  _NOTE_ if you need to add a custom key you can do it by prefixing your key by `x-{something}`
@@ -88,7 +88,7 @@ You can modify the `tags`, `paths`, and `components` keys on the generated docum
88
88
 
89
89
  #### How does it generate the others plugins documentation ?
90
90
 
91
- In other to reference a plugin's route into the documentation you need to add a `description` key in the `config` object.
91
+ In order to reference a plugin's route into the documentation you need to add a `description` key in the `config` object.
92
92
 
93
93
  For example this is the plugin email routes.json file
94
94
 
@@ -42,7 +42,8 @@ var documentation = {
42
42
  * That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI.
43
43
  */ const { major, minor, patch } = ctx.params;
44
44
  const version = major && minor && patch ? `${major}.${minor}.${patch}` : utils$1.getService('documentation').getDocumentationVersion();
45
- const openAPISpecsPath = path.join(strapi.dirs.app.extensions, 'documentation', 'documentation', version, 'full_documentation.json');
45
+ const extensionsDir = strapi.config.environment === 'production' ? strapi.dirs.dist.extensions : strapi.dirs.app.extensions;
46
+ const openAPISpecsPath = path.join(extensionsDir, 'documentation', 'documentation', version, 'full_documentation.json');
46
47
  try {
47
48
  const documentation = fs.readFileSync(openAPISpecsPath, 'utf8');
48
49
  const layout = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('../public/index.html.js')); })).default;
@@ -51,13 +52,13 @@ var documentation = {
51
52
  spec: JSON.stringify(JSON.parse(documentation))
52
53
  });
53
54
  try {
54
- const layoutPath = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public', 'index.html');
55
+ const layoutPath = path.resolve(extensionsDir, 'documentation', 'public', 'index.html');
55
56
  await fs.ensureFile(layoutPath);
56
57
  await fs.writeFile(layoutPath, filledLayout);
57
58
  // Serve the file.
58
59
  ctx.url = path.basename(`${ctx.url}/index.html`);
59
60
  try {
60
- const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');
61
+ const staticFolder = path.resolve(extensionsDir, 'documentation', 'public');
61
62
  return koaStatic(staticFolder)(ctx, next);
62
63
  } catch (e) {
63
64
  strapi.log.error(e);
@@ -1 +1 @@
1
- {"version":3,"file":"documentation.js","sources":["../../../server/src/controllers/documentation.ts"],"sourcesContent":["import path from 'path';\nimport bcrypt from 'bcryptjs';\nimport fs from 'fs-extra';\nimport _ from 'lodash';\nimport koaStatic from 'koa-static';\nimport { yup, validateYupSchema } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\n\nimport { getService } from '../utils';\nimport type { Config } from '../types';\n\nconst validation = {\n validateSettings: validateYupSchema(\n yup.object().shape({\n restrictedAccess: yup.boolean(),\n password: yup\n .string()\n .min(8)\n .matches(/[a-z]/, '${path} must contain at least one lowercase character')\n .matches(/[A-Z]/, '${path} must contain at least one uppercase character')\n .matches(/\\d/, '${path} must contain at least one number')\n .when('restrictedAccess', (value, initSchema) => {\n return value ? initSchema.required('password is required') : initSchema;\n }),\n })\n ),\n};\n\nexport default {\n async getInfos(ctx: Koa.Context) {\n try {\n const docService = getService('documentation');\n const docVersions = docService.getDocumentationVersions();\n const documentationAccess = await docService.getDocumentationAccess();\n\n ctx.send({\n docVersions,\n currentVersion: docService.getDocumentationVersion(),\n prefix: '/documentation',\n documentationAccess,\n });\n } catch (err) {\n strapi.log.error(err);\n ctx.badRequest();\n }\n },\n\n async index(ctx: Koa.Context, next: Koa.Next) {\n try {\n /**\n * We don't expose the specs using koa-static or something else due to security reasons.\n * That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI.\n */\n const { major, minor, patch } = ctx.params;\n const version =\n major && minor && patch\n ? `${major}.${minor}.${patch}`\n : getService('documentation').getDocumentationVersion();\n\n const openAPISpecsPath = path.join(\n strapi.dirs.app.extensions,\n 'documentation',\n 'documentation',\n version,\n 'full_documentation.json'\n );\n\n try {\n const documentation = fs.readFileSync(openAPISpecsPath, 'utf8');\n\n const layout = (await import('../public/index.html')).default;\n\n const filledLayout = _.template(layout)({\n backendUrl: strapi.config.server.url,\n spec: JSON.stringify(JSON.parse(documentation)),\n });\n\n try {\n const layoutPath = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public',\n 'index.html'\n );\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, filledLayout);\n\n // Serve the file.\n ctx.url = path.basename(`${ctx.url}/index.html`);\n\n try {\n const staticFolder = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public'\n );\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async loginView(ctx: Koa.Context, next: Koa.Next) {\n // lazy require cheerio\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const cheerio = require('cheerio');\n\n const { error } = ctx.query;\n\n try {\n const layout = (await import('../public/login.html')).default;\n\n const filledLayout = _.template(layout.toString())({\n actionUrl: `${strapi.config.server.url}/documentation/login`,\n });\n\n const $ = cheerio.load(filledLayout);\n\n $('.error').text(_.isEmpty(error) ? '' : 'Wrong password...');\n\n try {\n const layoutPath = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public',\n 'login.html'\n );\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, $.html());\n\n ctx.url = path.basename(`${ctx.url}/login.html`);\n\n try {\n const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async login(ctx: Koa.Context) {\n const {\n body: { password },\n } = ctx.request;\n\n const { password: hash } = (await strapi\n .store({ type: 'plugin', name: 'documentation', key: 'config' })\n .get()) as { password: string };\n\n const isValid = await bcrypt.compare(password, hash);\n\n let querystring = '?error=password';\n\n if (isValid && ctx.session) {\n ctx.session.documentation = {\n logged: true,\n };\n\n querystring = '';\n }\n\n ctx.redirect(`${strapi.config.server.url}/documentation${querystring}`);\n },\n\n async regenerateDoc(ctx: Koa.Context) {\n const { version } = ctx.request.body;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to generate does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.generateFullDoc(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async deleteDoc(ctx: Koa.Context) {\n const { version } = ctx.params;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to delete does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.deleteDocumentation(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async updateSettings(ctx: Koa.Context) {\n const pluginStore = strapi.store({ type: 'plugin', name: 'documentation' });\n\n const data = await validation.validateSettings(ctx.request.body);\n\n const config: Config = {\n restrictedAccess: Boolean(data.restrictedAccess),\n };\n\n if (data.password) {\n config.password = await bcrypt.hash(data.password, 10);\n }\n\n await pluginStore.set({ key: 'config', value: config });\n\n return ctx.send({ ok: true });\n },\n};\n"],"names":["validation","validateSettings","validateYupSchema","yup","object","shape","restrictedAccess","boolean","password","string","min","matches","when","value","initSchema","required","getInfos","ctx","docService","getService","docVersions","getDocumentationVersions","documentationAccess","getDocumentationAccess","send","currentVersion","getDocumentationVersion","prefix","err","strapi","log","error","badRequest","index","next","major","minor","patch","params","version","openAPISpecsPath","path","join","dirs","app","extensions","documentation","fs","readFileSync","layout","default","filledLayout","_","template","backendUrl","config","server","url","spec","JSON","stringify","parse","layoutPath","resolve","ensureFile","writeFile","basename","staticFolder","koaStatic","e","loginView","cheerio","require","query","toString","actionUrl","$","load","text","isEmpty","html","login","body","request","hash","store","type","name","key","get","isValid","bcrypt","compare","querystring","session","logged","redirect","regenerateDoc","service","documentationVersions","map","el","includes","reload","isWatching","generateFullDoc","ok","deleteDoc","deleteDocumentation","updateSettings","pluginStore","data","Boolean","set"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,UAAAA,GAAa;AACjBC,IAAAA,gBAAAA,EAAkBC,uBAAAA,CAChBC,SAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AACjBC,QAAAA,gBAAAA,EAAkBH,UAAII,OAAO,EAAA;QAC7BC,QAAAA,EAAUL,SAAAA,CACPM,MAAM,EAAA,CACNC,GAAG,CAAC,CAAA,CAAA,CACJC,OAAO,CAAC,OAAA,EAAS,uDAAA,CAAA,CACjBA,OAAO,CAAC,OAAA,EAAS,uDAAA,CAAA,CACjBA,OAAO,CAAC,IAAA,EAAM,4CACdC,IAAI,CAAC,kBAAA,EAAoB,CAACC,KAAAA,EAAOC,UAAAA,GAAAA;AAChC,YAAA,OAAOD,KAAAA,GAAQC,UAAAA,CAAWC,QAAQ,CAAC,sBAAA,CAAA,GAA0BD,UAAAA;AAC/D,QAAA,CAAA;AACJ,KAAA,CAAA;AAEJ,CAAA;AAEA,oBAAe;AACb,IAAA,MAAME,UAASC,GAAgB,EAAA;QAC7B,IAAI;AACF,YAAA,MAAMC,aAAaC,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,MAAMsG,WAAAA,CAAYG,GAAG,CAAC;YAAEzB,GAAAA,EAAK,QAAA;YAAU3E,KAAAA,EAAO0C;AAAO,SAAA,CAAA;QAErD,OAAOtC,GAAAA,CAAIO,IAAI,CAAC;YAAEkF,EAAAA,EAAI;AAAK,SAAA,CAAA;AAC7B,IAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"documentation.js","sources":["../../../server/src/controllers/documentation.ts"],"sourcesContent":["import path from 'path';\nimport bcrypt from 'bcryptjs';\nimport fs from 'fs-extra';\nimport _ from 'lodash';\nimport koaStatic from 'koa-static';\nimport { yup, validateYupSchema } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\n\nimport { getService } from '../utils';\nimport type { Config } from '../types';\n\nconst validation = {\n validateSettings: validateYupSchema(\n yup.object().shape({\n restrictedAccess: yup.boolean(),\n password: yup\n .string()\n .min(8)\n .matches(/[a-z]/, '${path} must contain at least one lowercase character')\n .matches(/[A-Z]/, '${path} must contain at least one uppercase character')\n .matches(/\\d/, '${path} must contain at least one number')\n .when('restrictedAccess', (value, initSchema) => {\n return value ? initSchema.required('password is required') : initSchema;\n }),\n })\n ),\n};\n\nexport default {\n async getInfos(ctx: Koa.Context) {\n try {\n const docService = getService('documentation');\n const docVersions = docService.getDocumentationVersions();\n const documentationAccess = await docService.getDocumentationAccess();\n\n ctx.send({\n docVersions,\n currentVersion: docService.getDocumentationVersion(),\n prefix: '/documentation',\n documentationAccess,\n });\n } catch (err) {\n strapi.log.error(err);\n ctx.badRequest();\n }\n },\n\n async index(ctx: Koa.Context, next: Koa.Next) {\n try {\n /**\n * We don't expose the specs using koa-static or something else due to security reasons.\n * That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI.\n */\n const { major, minor, patch } = ctx.params;\n const version =\n major && minor && patch\n ? `${major}.${minor}.${patch}`\n : getService('documentation').getDocumentationVersion();\n\n const extensionsDir =\n strapi.config.environment === 'production'\n ? strapi.dirs.dist.extensions\n : strapi.dirs.app.extensions;\n\n const openAPISpecsPath = path.join(\n extensionsDir,\n 'documentation',\n 'documentation',\n version,\n 'full_documentation.json'\n );\n\n try {\n const documentation = fs.readFileSync(openAPISpecsPath, 'utf8');\n\n const layout = (await import('../public/index.html')).default;\n\n const filledLayout = _.template(layout)({\n backendUrl: strapi.config.server.url,\n spec: JSON.stringify(JSON.parse(documentation)),\n });\n\n try {\n const layoutPath = path.resolve(extensionsDir, 'documentation', 'public', 'index.html');\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, filledLayout);\n\n // Serve the file.\n ctx.url = path.basename(`${ctx.url}/index.html`);\n\n try {\n const staticFolder = path.resolve(extensionsDir, 'documentation', 'public');\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async loginView(ctx: Koa.Context, next: Koa.Next) {\n // lazy require cheerio\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const cheerio = require('cheerio');\n\n const { error } = ctx.query;\n\n try {\n const layout = (await import('../public/login.html')).default;\n\n const filledLayout = _.template(layout.toString())({\n actionUrl: `${strapi.config.server.url}/documentation/login`,\n });\n\n const $ = cheerio.load(filledLayout);\n\n $('.error').text(_.isEmpty(error) ? '' : 'Wrong password...');\n\n try {\n const layoutPath = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public',\n 'login.html'\n );\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, $.html());\n\n ctx.url = path.basename(`${ctx.url}/login.html`);\n\n try {\n const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async login(ctx: Koa.Context) {\n const {\n body: { password },\n } = ctx.request;\n\n const { password: hash } = (await strapi\n .store({ type: 'plugin', name: 'documentation', key: 'config' })\n .get()) as { password: string };\n\n const isValid = await bcrypt.compare(password, hash);\n\n let querystring = '?error=password';\n\n if (isValid && ctx.session) {\n ctx.session.documentation = {\n logged: true,\n };\n\n querystring = '';\n }\n\n ctx.redirect(`${strapi.config.server.url}/documentation${querystring}`);\n },\n\n async regenerateDoc(ctx: Koa.Context) {\n const { version } = ctx.request.body;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to generate does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.generateFullDoc(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async deleteDoc(ctx: Koa.Context) {\n const { version } = ctx.params;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to delete does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.deleteDocumentation(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async updateSettings(ctx: Koa.Context) {\n const pluginStore = strapi.store({ type: 'plugin', name: 'documentation' });\n\n const data = await validation.validateSettings(ctx.request.body);\n\n const config: Config = {\n restrictedAccess: Boolean(data.restrictedAccess),\n };\n\n if (data.password) {\n config.password = await bcrypt.hash(data.password, 10);\n }\n\n await pluginStore.set({ key: 'config', value: config });\n\n return ctx.send({ ok: true });\n },\n};\n"],"names":["validation","validateSettings","validateYupSchema","yup","object","shape","restrictedAccess","boolean","password","string","min","matches","when","value","initSchema","required","getInfos","ctx","docService","getService","docVersions","getDocumentationVersions","documentationAccess","getDocumentationAccess","send","currentVersion","getDocumentationVersion","prefix","err","strapi","log","error","badRequest","index","next","major","minor","patch","params","version","extensionsDir","config","environment","dirs","dist","extensions","app","openAPISpecsPath","path","join","documentation","fs","readFileSync","layout","default","filledLayout","_","template","backendUrl","server","url","spec","JSON","stringify","parse","layoutPath","resolve","ensureFile","writeFile","basename","staticFolder","koaStatic","e","loginView","cheerio","require","query","toString","actionUrl","$","load","text","isEmpty","html","login","body","request","hash","store","type","name","key","get","isValid","bcrypt","compare","querystring","session","logged","redirect","regenerateDoc","service","documentationVersions","map","el","includes","reload","isWatching","generateFullDoc","ok","deleteDoc","deleteDocumentation","updateSettings","pluginStore","data","Boolean","set"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,UAAAA,GAAa;AACjBC,IAAAA,gBAAAA,EAAkBC,uBAAAA,CAChBC,SAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AACjBC,QAAAA,gBAAAA,EAAkBH,UAAII,OAAO,EAAA;QAC7BC,QAAAA,EAAUL,SAAAA,CACPM,MAAM,EAAA,CACNC,GAAG,CAAC,CAAA,CAAA,CACJC,OAAO,CAAC,OAAA,EAAS,uDAAA,CAAA,CACjBA,OAAO,CAAC,OAAA,EAAS,uDAAA,CAAA,CACjBA,OAAO,CAAC,IAAA,EAAM,4CACdC,IAAI,CAAC,kBAAA,EAAoB,CAACC,KAAAA,EAAOC,UAAAA,GAAAA;AAChC,YAAA,OAAOD,KAAAA,GAAQC,UAAAA,CAAWC,QAAQ,CAAC,sBAAA,CAAA,GAA0BD,UAAAA;AAC/D,QAAA,CAAA;AACJ,KAAA,CAAA;AAEJ,CAAA;AAEA,oBAAe;AACb,IAAA,MAAME,UAASC,GAAgB,EAAA;QAC7B,IAAI;AACF,YAAA,MAAMC,aAAaC,kBAAAA,CAAW,eAAA,CAAA;YAC9B,MAAMC,WAAAA,GAAcF,WAAWG,wBAAwB,EAAA;YACvD,MAAMC,mBAAAA,GAAsB,MAAMJ,UAAAA,CAAWK,sBAAsB,EAAA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CAAA;QAErD,OAAOxB,GAAAA,CAAIO,IAAI,CAAC;YAAEqF,EAAAA,EAAI;AAAK,SAAA,CAAA;AAC7B,IAAA;AACF,CAAA;;;;"}
@@ -38,7 +38,8 @@ var documentation = {
38
38
  * That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI.
39
39
  */ const { major, minor, patch } = ctx.params;
40
40
  const version = major && minor && patch ? `${major}.${minor}.${patch}` : getService('documentation').getDocumentationVersion();
41
- const openAPISpecsPath = path.join(strapi.dirs.app.extensions, 'documentation', 'documentation', version, 'full_documentation.json');
41
+ const extensionsDir = strapi.config.environment === 'production' ? strapi.dirs.dist.extensions : strapi.dirs.app.extensions;
42
+ const openAPISpecsPath = path.join(extensionsDir, 'documentation', 'documentation', version, 'full_documentation.json');
42
43
  try {
43
44
  const documentation = fs.readFileSync(openAPISpecsPath, 'utf8');
44
45
  const layout = (await import('../public/index.html.mjs')).default;
@@ -47,13 +48,13 @@ var documentation = {
47
48
  spec: JSON.stringify(JSON.parse(documentation))
48
49
  });
49
50
  try {
50
- const layoutPath = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public', 'index.html');
51
+ const layoutPath = path.resolve(extensionsDir, 'documentation', 'public', 'index.html');
51
52
  await fs.ensureFile(layoutPath);
52
53
  await fs.writeFile(layoutPath, filledLayout);
53
54
  // Serve the file.
54
55
  ctx.url = path.basename(`${ctx.url}/index.html`);
55
56
  try {
56
- const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');
57
+ const staticFolder = path.resolve(extensionsDir, 'documentation', 'public');
57
58
  return koaStatic(staticFolder)(ctx, next);
58
59
  } catch (e) {
59
60
  strapi.log.error(e);
@@ -1 +1 @@
1
- {"version":3,"file":"documentation.mjs","sources":["../../../server/src/controllers/documentation.ts"],"sourcesContent":["import path from 'path';\nimport bcrypt from 'bcryptjs';\nimport fs from 'fs-extra';\nimport _ from 'lodash';\nimport koaStatic from 'koa-static';\nimport { yup, validateYupSchema } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\n\nimport { getService } from '../utils';\nimport type { Config } from '../types';\n\nconst validation = {\n validateSettings: validateYupSchema(\n yup.object().shape({\n restrictedAccess: yup.boolean(),\n password: yup\n .string()\n .min(8)\n .matches(/[a-z]/, '${path} must contain at least one lowercase character')\n .matches(/[A-Z]/, '${path} must contain at least one uppercase character')\n .matches(/\\d/, '${path} must contain at least one number')\n .when('restrictedAccess', (value, initSchema) => {\n return value ? initSchema.required('password is required') : initSchema;\n }),\n })\n ),\n};\n\nexport default {\n async getInfos(ctx: Koa.Context) {\n try {\n const docService = getService('documentation');\n const docVersions = docService.getDocumentationVersions();\n const documentationAccess = await docService.getDocumentationAccess();\n\n ctx.send({\n docVersions,\n currentVersion: docService.getDocumentationVersion(),\n prefix: '/documentation',\n documentationAccess,\n });\n } catch (err) {\n strapi.log.error(err);\n ctx.badRequest();\n }\n },\n\n async index(ctx: Koa.Context, next: Koa.Next) {\n try {\n /**\n * We don't expose the specs using koa-static or something else due to security reasons.\n * That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI.\n */\n const { major, minor, patch } = ctx.params;\n const version =\n major && minor && patch\n ? `${major}.${minor}.${patch}`\n : getService('documentation').getDocumentationVersion();\n\n const openAPISpecsPath = path.join(\n strapi.dirs.app.extensions,\n 'documentation',\n 'documentation',\n version,\n 'full_documentation.json'\n );\n\n try {\n const documentation = fs.readFileSync(openAPISpecsPath, 'utf8');\n\n const layout = (await import('../public/index.html')).default;\n\n const filledLayout = _.template(layout)({\n backendUrl: strapi.config.server.url,\n spec: JSON.stringify(JSON.parse(documentation)),\n });\n\n try {\n const layoutPath = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public',\n 'index.html'\n );\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, filledLayout);\n\n // Serve the file.\n ctx.url = path.basename(`${ctx.url}/index.html`);\n\n try {\n const staticFolder = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public'\n );\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async loginView(ctx: Koa.Context, next: Koa.Next) {\n // lazy require cheerio\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const cheerio = require('cheerio');\n\n const { error } = ctx.query;\n\n try {\n const layout = (await import('../public/login.html')).default;\n\n const filledLayout = _.template(layout.toString())({\n actionUrl: `${strapi.config.server.url}/documentation/login`,\n });\n\n const $ = cheerio.load(filledLayout);\n\n $('.error').text(_.isEmpty(error) ? '' : 'Wrong password...');\n\n try {\n const layoutPath = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public',\n 'login.html'\n );\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, $.html());\n\n ctx.url = path.basename(`${ctx.url}/login.html`);\n\n try {\n const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async login(ctx: Koa.Context) {\n const {\n body: { password },\n } = ctx.request;\n\n const { password: hash } = (await strapi\n .store({ type: 'plugin', name: 'documentation', key: 'config' })\n .get()) as { password: string };\n\n const isValid = await bcrypt.compare(password, hash);\n\n let querystring = '?error=password';\n\n if (isValid && ctx.session) {\n ctx.session.documentation = {\n logged: true,\n };\n\n querystring = '';\n }\n\n ctx.redirect(`${strapi.config.server.url}/documentation${querystring}`);\n },\n\n async regenerateDoc(ctx: Koa.Context) {\n const { version } = ctx.request.body;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to generate does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.generateFullDoc(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async deleteDoc(ctx: Koa.Context) {\n const { version } = ctx.params;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to delete does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.deleteDocumentation(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async updateSettings(ctx: Koa.Context) {\n const pluginStore = strapi.store({ type: 'plugin', name: 'documentation' });\n\n const data = await validation.validateSettings(ctx.request.body);\n\n const config: Config = {\n restrictedAccess: Boolean(data.restrictedAccess),\n };\n\n if (data.password) {\n config.password = await bcrypt.hash(data.password, 10);\n }\n\n await pluginStore.set({ key: 'config', value: config });\n\n return ctx.send({ ok: true });\n },\n};\n"],"names":["validation","validateSettings","validateYupSchema","yup","object","shape","restrictedAccess","boolean","password","string","min","matches","when","value","initSchema","required","getInfos","ctx","docService","getService","docVersions","getDocumentationVersions","documentationAccess","getDocumentationAccess","send","currentVersion","getDocumentationVersion","prefix","err","strapi","log","error","badRequest","index","next","major","minor","patch","params","version","openAPISpecsPath","path","join","dirs","app","extensions","documentation","fs","readFileSync","layout","default","filledLayout","_","template","backendUrl","config","server","url","spec","JSON","stringify","parse","layoutPath","resolve","ensureFile","writeFile","basename","staticFolder","koaStatic","e","loginView","cheerio","require","query","toString","actionUrl","$","load","text","isEmpty","html","login","body","request","hash","store","type","name","key","get","isValid","bcrypt","compare","querystring","session","logged","redirect","regenerateDoc","service","documentationVersions","map","el","includes","reload","isWatching","generateFullDoc","ok","deleteDoc","deleteDocumentation","updateSettings","pluginStore","data","Boolean","set"],"mappings":";;;;;;;;AAaA,MAAMA,UAAAA,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R7E,MAAAA,CAAO0E,MAAM,CAACC,UAAU,GAAG,IAAA;AAC7B,QAAA;AACF,IAAA,CAAA;AAEA,IAAA,MAAMK,gBAAe5F,GAAgB,EAAA;QACnC,MAAM6F,WAAAA,GAAcjF,MAAAA,CAAOwD,KAAK,CAAC;YAAEC,IAAAA,EAAM,QAAA;YAAUC,IAAAA,EAAM;AAAgB,SAAA,CAAA;QAEzE,MAAMwB,IAAAA,GAAO,MAAM/G,UAAAA,CAAWC,gBAAgB,CAACgB,GAAAA,CAAIkE,OAAO,CAACD,IAAI,CAAA;AAE/D,QAAA,MAAM3B,MAAAA,GAAiB;YACrBjD,gBAAAA,EAAkB0G,OAAAA,CAAQD,KAAKzG,gBAAgB;AACjD,SAAA;QAEA,IAAIyG,IAAAA,CAAKvG,QAAQ,EAAE;YACjB+C,MAAAA,CAAO/C,QAAQ,GAAG,MAAMmF,MAAAA,CAAOP,IAAI,CAAC2B,IAAAA,CAAKvG,QAAQ,EAAE,EAAA,CAAA;AACrD,QAAA;QAEA,MAAMsG,WAAAA,CAAYG,GAAG,CAAC;YAAEzB,GAAAA,EAAK,QAAA;YAAU3E,KAAAA,EAAO0C;AAAO,SAAA,CAAA;QAErD,OAAOtC,GAAAA,CAAIO,IAAI,CAAC;YAAEkF,EAAAA,EAAI;AAAK,SAAA,CAAA;AAC7B,IAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"documentation.mjs","sources":["../../../server/src/controllers/documentation.ts"],"sourcesContent":["import path from 'path';\nimport bcrypt from 'bcryptjs';\nimport fs from 'fs-extra';\nimport _ from 'lodash';\nimport koaStatic from 'koa-static';\nimport { yup, validateYupSchema } from '@strapi/utils';\n\nimport type Koa from 'koa';\nimport type {} from 'koa-body';\n\nimport { getService } from '../utils';\nimport type { Config } from '../types';\n\nconst validation = {\n validateSettings: validateYupSchema(\n yup.object().shape({\n restrictedAccess: yup.boolean(),\n password: yup\n .string()\n .min(8)\n .matches(/[a-z]/, '${path} must contain at least one lowercase character')\n .matches(/[A-Z]/, '${path} must contain at least one uppercase character')\n .matches(/\\d/, '${path} must contain at least one number')\n .when('restrictedAccess', (value, initSchema) => {\n return value ? initSchema.required('password is required') : initSchema;\n }),\n })\n ),\n};\n\nexport default {\n async getInfos(ctx: Koa.Context) {\n try {\n const docService = getService('documentation');\n const docVersions = docService.getDocumentationVersions();\n const documentationAccess = await docService.getDocumentationAccess();\n\n ctx.send({\n docVersions,\n currentVersion: docService.getDocumentationVersion(),\n prefix: '/documentation',\n documentationAccess,\n });\n } catch (err) {\n strapi.log.error(err);\n ctx.badRequest();\n }\n },\n\n async index(ctx: Koa.Context, next: Koa.Next) {\n try {\n /**\n * We don't expose the specs using koa-static or something else due to security reasons.\n * That's why, we need to read the file localy and send the specs through it when we serve the Swagger UI.\n */\n const { major, minor, patch } = ctx.params;\n const version =\n major && minor && patch\n ? `${major}.${minor}.${patch}`\n : getService('documentation').getDocumentationVersion();\n\n const extensionsDir =\n strapi.config.environment === 'production'\n ? strapi.dirs.dist.extensions\n : strapi.dirs.app.extensions;\n\n const openAPISpecsPath = path.join(\n extensionsDir,\n 'documentation',\n 'documentation',\n version,\n 'full_documentation.json'\n );\n\n try {\n const documentation = fs.readFileSync(openAPISpecsPath, 'utf8');\n\n const layout = (await import('../public/index.html')).default;\n\n const filledLayout = _.template(layout)({\n backendUrl: strapi.config.server.url,\n spec: JSON.stringify(JSON.parse(documentation)),\n });\n\n try {\n const layoutPath = path.resolve(extensionsDir, 'documentation', 'public', 'index.html');\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, filledLayout);\n\n // Serve the file.\n ctx.url = path.basename(`${ctx.url}/index.html`);\n\n try {\n const staticFolder = path.resolve(extensionsDir, 'documentation', 'public');\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async loginView(ctx: Koa.Context, next: Koa.Next) {\n // lazy require cheerio\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const cheerio = require('cheerio');\n\n const { error } = ctx.query;\n\n try {\n const layout = (await import('../public/login.html')).default;\n\n const filledLayout = _.template(layout.toString())({\n actionUrl: `${strapi.config.server.url}/documentation/login`,\n });\n\n const $ = cheerio.load(filledLayout);\n\n $('.error').text(_.isEmpty(error) ? '' : 'Wrong password...');\n\n try {\n const layoutPath = path.resolve(\n strapi.dirs.app.extensions,\n 'documentation',\n 'public',\n 'login.html'\n );\n await fs.ensureFile(layoutPath);\n await fs.writeFile(layoutPath, $.html());\n\n ctx.url = path.basename(`${ctx.url}/login.html`);\n\n try {\n const staticFolder = path.resolve(strapi.dirs.app.extensions, 'documentation', 'public');\n return koaStatic(staticFolder)(ctx, next);\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n } catch (e) {\n strapi.log.error(e);\n }\n },\n\n async login(ctx: Koa.Context) {\n const {\n body: { password },\n } = ctx.request;\n\n const { password: hash } = (await strapi\n .store({ type: 'plugin', name: 'documentation', key: 'config' })\n .get()) as { password: string };\n\n const isValid = await bcrypt.compare(password, hash);\n\n let querystring = '?error=password';\n\n if (isValid && ctx.session) {\n ctx.session.documentation = {\n logged: true,\n };\n\n querystring = '';\n }\n\n ctx.redirect(`${strapi.config.server.url}/documentation${querystring}`);\n },\n\n async regenerateDoc(ctx: Koa.Context) {\n const { version } = ctx.request.body;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to generate does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.generateFullDoc(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async deleteDoc(ctx: Koa.Context) {\n const { version } = ctx.params;\n\n const service = getService('documentation');\n\n const documentationVersions = service.getDocumentationVersions().map((el) => el.version);\n\n if (_.isEmpty(version)) {\n return ctx.badRequest('Please provide a version.');\n }\n\n if (!documentationVersions.includes(version)) {\n return ctx.badRequest('The version you are trying to delete does not exist.');\n }\n\n try {\n strapi.reload.isWatching = false;\n await service.deleteDocumentation(version);\n ctx.send({ ok: true });\n } finally {\n strapi.reload.isWatching = true;\n }\n },\n\n async updateSettings(ctx: Koa.Context) {\n const pluginStore = strapi.store({ type: 'plugin', name: 'documentation' });\n\n const data = await validation.validateSettings(ctx.request.body);\n\n const config: Config = {\n restrictedAccess: Boolean(data.restrictedAccess),\n };\n\n if (data.password) {\n config.password = await bcrypt.hash(data.password, 10);\n }\n\n await pluginStore.set({ key: 'config', value: config });\n\n return ctx.send({ ok: true });\n },\n};\n"],"names":["validation","validateSettings","validateYupSchema","yup","object","shape","restrictedAccess","boolean","password","string","min","matches","when","value","initSchema","required","getInfos","ctx","docService","getService","docVersions","getDocumentationVersions","documentationAccess","getDocumentationAccess","send","currentVersion","getDocumentationVersion","prefix","err","strapi","log","error","badRequest","index","next","major","minor","patch","params","version","extensionsDir","config","environment","dirs","dist","extensions","app","openAPISpecsPath","path","join","documentation","fs","readFileSync","layout","default","filledLayout","_","template","backendUrl","server","url","spec","JSON","stringify","parse","layoutPath","resolve","ensureFile","writeFile","basename","staticFolder","koaStatic","e","loginView","cheerio","require","query","toString","actionUrl","$","load","text","isEmpty","html","login","body","request","hash","store","type","name","key","get","isValid","bcrypt","compare","querystring","session","logged","redirect","regenerateDoc","service","documentationVersions","map","el","includes","reload","isWatching","generateFullDoc","ok","deleteDoc","deleteDocumentation","updateSettings","pluginStore","data","Boolean","set"],"mappings":";;;;;;;;AAaA,MAAMA,UAAAA,GAAa;AACjBC,IAAAA,gBAAAA,EAAkBC,iBAAAA,CAChBC,GAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AACjBC,QAAAA,gBAAAA,EAAkBH,IAAII,OAAO,EAAA;QAC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GAAgB,EAAA;QACnC,MAAMgG,WAAAA,GAAcpF,MAAAA,CAAO2D,KAAK,CAAC;YAAEC,IAAAA,EAAM,QAAA;YAAUC,IAAAA,EAAM;AAAgB,SAAA,CAAA;QAEzE,MAAMwB,IAAAA,GAAO,MAAMlH,UAAAA,CAAWC,gBAAgB,CAACgB,GAAAA,CAAIqE,OAAO,CAACD,IAAI,CAAA;AAE/D,QAAA,MAAM5C,MAAAA,GAAiB;YACrBnC,gBAAAA,EAAkB6G,OAAAA,CAAQD,KAAK5G,gBAAgB;AACjD,SAAA;QAEA,IAAI4G,IAAAA,CAAK1G,QAAQ,EAAE;YACjBiC,MAAAA,CAAOjC,QAAQ,GAAG,MAAMsF,MAAAA,CAAOP,IAAI,CAAC2B,IAAAA,CAAK1G,QAAQ,EAAE,EAAA,CAAA;AACrD,QAAA;QAEA,MAAMyG,WAAAA,CAAYG,GAAG,CAAC;YAAEzB,GAAAA,EAAK,QAAA;YAAU9E,KAAAA,EAAO4B;AAAO,SAAA,CAAA;QAErD,OAAOxB,GAAAA,CAAIO,IAAI,CAAC;YAAEqF,EAAAA,EAAI;AAAK,SAAA,CAAA;AAC7B,IAAA;AACF,CAAA;;;;"}
@@ -17,7 +17,10 @@ const createService = ({ strapi })=>{
17
17
  return config.info.version;
18
18
  },
19
19
  getFullDocumentationPath () {
20
- return path.join(strapi.dirs.app.extensions, 'documentation', 'documentation');
20
+ // In production, documentation files live under dist/src/extensions/
21
+ // after the build step. Use dist.extensions for reading.
22
+ const extensionsDir = strapi.config.environment === 'production' ? strapi.dirs.dist.extensions : strapi.dirs.app.extensions;
23
+ return path.join(extensionsDir, 'documentation', 'documentation');
21
24
  },
22
25
  getDocumentationVersions () {
23
26
  return fs.readdirSync(this.getFullDocumentationPath()).map((version)=>{
@@ -49,10 +52,13 @@ const createService = ({ strapi })=>{
49
52
  };
50
53
  },
51
54
  getApiDocumentationPath (api) {
55
+ const isProduction = strapi.config.environment === 'production';
52
56
  if (api.getter === 'plugin') {
53
- return path.join(strapi.dirs.app.extensions, api.name, 'documentation');
57
+ const extensionsDir = isProduction ? strapi.dirs.dist.extensions : strapi.dirs.app.extensions;
58
+ return path.join(extensionsDir, api.name, 'documentation');
54
59
  }
55
- return path.join(strapi.dirs.app.api, api.name, 'documentation');
60
+ const apiDir = isProduction ? strapi.dirs.dist.api : strapi.dirs.app.api;
61
+ return path.join(apiDir, api.name, 'documentation');
56
62
  },
57
63
  async deleteDocumentation (version) {
58
64
  const apis = this.getPluginAndApiInfo();
@@ -1 +1 @@
1
- {"version":3,"file":"documentation.js","sources":["../../../server/src/services/documentation.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { produce } from 'immer';\nimport type { Core } from '@strapi/types';\n\nimport { builApiEndpointPath, buildComponentSchema } from './helpers';\nimport { getPluginsThatNeedDocumentation } from './utils/get-plugins-that-need-documentation';\nimport { getService } from '../utils';\n\nimport type { Config, PluginConfig } from '../types';\n\nexport type Version = {\n version: string;\n generatedDate: string;\n url: string;\n};\n\nexport type DocumentationService = ReturnType<typeof createService>;\n\nconst createService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = strapi.config.get('plugin::documentation') as PluginConfig;\n const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(config);\n const overrideService = getService('override');\n\n return {\n getDocumentationVersion() {\n return config.info.version;\n },\n\n getFullDocumentationPath() {\n return path.join(strapi.dirs.app.extensions, 'documentation', 'documentation');\n },\n\n getDocumentationVersions(): Version[] {\n return fs\n .readdirSync(this.getFullDocumentationPath())\n .map((version) => {\n try {\n const filePath = path.resolve(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n\n const doc = JSON.parse(fs.readFileSync(filePath).toString());\n\n const generatedDate = doc.info['x-generation-date'];\n\n return { version, generatedDate, url: '' };\n } catch (err) {\n return null;\n }\n })\n .filter((x) => x) as Version[];\n },\n\n /**\n * Returns settings stored in core-store\n */\n async getDocumentationAccess() {\n const { restrictedAccess } = (await strapi.store!({\n environment: '',\n type: 'plugin',\n name: 'documentation',\n key: 'config',\n }).get()) as Config;\n\n return { restrictedAccess };\n },\n\n getApiDocumentationPath(api: { name: string; getter: string }) {\n if (api.getter === 'plugin') {\n return path.join(strapi.dirs.app.extensions, api.name, 'documentation');\n }\n\n return path.join(strapi.dirs.app.api, api.name, 'documentation');\n },\n\n async deleteDocumentation(version: string) {\n const apis = this.getPluginAndApiInfo();\n for (const api of apis) {\n await fs.remove(path.join(this.getApiDocumentationPath(api), version));\n }\n\n await fs.remove(path.join(this.getFullDocumentationPath(), version));\n },\n\n getPluginAndApiInfo() {\n const pluginsToDocument = pluginsThatNeedDocumentation.map((plugin) => {\n return {\n name: plugin,\n getter: 'plugin',\n ctNames: Object.keys(strapi.plugin(plugin).contentTypes),\n };\n });\n\n const apisToDocument = Object.keys(strapi.apis).map((api) => {\n return {\n name: api,\n getter: 'api',\n ctNames: Object.keys(strapi.api(api).contentTypes),\n };\n });\n\n return [...apisToDocument, ...pluginsToDocument];\n },\n\n /**\n * @description - Creates the Swagger json files\n */\n async generateFullDoc(versionOpt?: string) {\n const version = versionOpt ?? this.getDocumentationVersion();\n\n const apis = this.getPluginAndApiInfo();\n const apisThatNeedGeneratedDocumentation = apis.filter(\n ({ name }) => !overrideService.isEnabled(name)\n );\n\n // Initialize the generated documentation with defaults\n const generatedDocumentation = await produce(config, async (draft) => {\n if (draft.servers?.length === 0) {\n // When no servers found set the defaults\n const serverUrl = strapi.config.get('server.absoluteUrl');\n const apiPath = strapi.config.get('api.rest.prefix');\n draft.servers = [\n {\n url: `${serverUrl}${apiPath}`,\n description: 'Development server',\n },\n ];\n }\n\n if (!draft.components) {\n draft.components = {};\n }\n\n // Set the generated date\n draft.info['x-generation-date'] = new Date().toISOString();\n // Set the plugins that need documentation\n draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;\n\n // Delete the mutateDocumentation key from the config so it doesn't end up in the spec\n delete draft['x-strapi-config'].mutateDocumentation;\n\n // Generate the documentation for each api and update the generatedDocumentation\n for (const api of apisThatNeedGeneratedDocumentation) {\n const newApiPath = builApiEndpointPath(api);\n const generatedSchemas = buildComponentSchema(api);\n\n if (generatedSchemas) {\n draft.components.schemas = { ...draft.components.schemas, ...generatedSchemas };\n }\n\n if (newApiPath) {\n draft.paths = { ...draft.paths, ...newApiPath };\n }\n }\n\n // When overrides are present update the generatedDocumentation\n if (overrideService.registeredOverrides.length > 0) {\n overrideService.registeredOverrides.forEach((override: Partial<PluginConfig>) => {\n // Only run the overrrides when no override version is provided,\n // or when the generated documentation version matches the override version\n if (!override?.info?.version || override.info.version === version) {\n if (override.tags) {\n // Merge override tags with the generated tags\n draft.tags = draft.tags || [];\n draft.tags.push(...override.tags);\n }\n\n if (override.paths) {\n // Merge override paths with the generated paths\n // The override will add a new path or replace the value of an existing path\n draft.paths = { ...draft.paths, ...override.paths };\n }\n\n if (override.components) {\n const keys = Object.keys(override.components) as Array<\n keyof typeof override.components\n >;\n\n keys.forEach((overrideKey) => {\n draft.components = draft.components || {};\n\n const overrideValue = override.components?.[overrideKey];\n const originalValue = draft.components?.[overrideKey];\n\n Object.assign(draft.components, {\n [overrideKey]: {\n ...originalValue,\n ...overrideValue,\n },\n });\n });\n }\n }\n });\n }\n });\n\n // Escape hatch, allow the user to provide a mutateDocumentation function that can alter any part of\n // the generated documentation before it is written to the file system\n const userMutatesDocumentation = config['x-strapi-config'].mutateDocumentation;\n\n const finalDocumentation = userMutatesDocumentation\n ? produce(generatedDocumentation, userMutatesDocumentation)\n : generatedDocumentation;\n\n // Get the file path for the final documentation\n const fullDocJsonPath = path.join(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n // Write the documentation to the file system\n await fs.ensureFile(fullDocJsonPath);\n await fs.writeJson(fullDocJsonPath, finalDocumentation, { spaces: 2 });\n },\n };\n};\n\nexport default createService;\n"],"names":["createService","strapi","config","get","pluginsThatNeedDocumentation","getPluginsThatNeedDocumentation","overrideService","getService","getDocumentationVersion","info","version","getFullDocumentationPath","path","join","dirs","app","extensions","getDocumentationVersions","fs","readdirSync","map","filePath","resolve","doc","JSON","parse","readFileSync","toString","generatedDate","url","err","filter","x","getDocumentationAccess","restrictedAccess","store","environment","type","name","key","getApiDocumentationPath","api","getter","deleteDocumentation","apis","getPluginAndApiInfo","remove","pluginsToDocument","plugin","ctNames","Object","keys","contentTypes","apisToDocument","generateFullDoc","versionOpt","apisThatNeedGeneratedDocumentation","isEnabled","generatedDocumentation","produce","draft","servers","length","serverUrl","apiPath","description","components","Date","toISOString","plugins","mutateDocumentation","newApiPath","builApiEndpointPath","generatedSchemas","buildComponentSchema","schemas","paths","registeredOverrides","forEach","override","tags","push","overrideKey","overrideValue","originalValue","assign","userMutatesDocumentation","finalDocumentation","fullDocJsonPath","ensureFile","writeJson","spaces"],"mappings":";;;;;;;;;;AAmBA,MAAMA,aAAAA,GAAgB,CAAC,EAAEC,MAAM,EAA2B,GAAA;AACxD,IAAA,MAAMC,MAAAA,GAASD,MAAAA,CAAOC,MAAM,CAACC,GAAG,CAAC,uBAAA,CAAA;AACjC,IAAA,MAAMC,+BAA+BC,+DAAAA,CAAgCH,MAAAA,CAAAA;AACrE,IAAA,MAAMI,kBAAkBC,gBAAAA,CAAW,UAAA,CAAA;IAEnC,OAAO;AACLC,QAAAA,uBAAAA,CAAAA,GAAAA;YACE,OAAON,MAAAA,CAAOO,IAAI,CAACC,OAAO;AAC5B,QAAA,CAAA;AAEAC,QAAAA,wBAAAA,CAAAA,GAAAA;YACE,OAAOC,IAAAA,CAAKC,IAAI,CAACZ,MAAAA,CAAOa,IAAI,CAACC,GAAG,CAACC,UAAU,EAAE,eAAA,EAAiB,eAAA,CAAA;AAChE,QAAA,CAAA;AAEAC,QAAAA,wBAAAA,CAAAA,GAAAA;YACE,OAAOC,EAAAA,CACJC,WAAW,CAAC,IAAI,CAACR,wBAAwB,EAAA,CAAA,CACzCS,GAAG,CAAC,CAACV,OAAAA,GAAAA;gBACJ,IAAI;oBACF,MAAMW,QAAA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,OAAO,CAAC,CAACI,WAAAA,GAAAA;AACZtB,oCAAAA,KAAAA,CAAMM,UAAU,GAAGN,KAAAA,CAAMM,UAAU,IAAI,EAAC;AAExC,oCAAA,MAAMiB,aAAAA,GAAgBJ,QAAAA,CAASb,UAAU,GAAGgB,WAAAA,CAAY;AACxD,oCAAA,MAAME,aAAAA,GAAgBxB,KAAAA,CAAMM,UAAU,GAAGgB,WAAAA,CAAY;AAErDhC,oCAAAA,MAAAA,CAAOmC,MAAM,CAACzB,KAAAA,CAAMM,UAAU,EAAE;AAC9B,wCAAA,CAACgB,cAAc;AACb,4CAAA,GAAGE,aAAa;AAChB,4CAAA,GAAGD;AACL;AACF,qCAAA,CAAA;AACF,gCAAA,CAAA,CAAA;AACF,4BAAA;AACF,wBAAA;AACF,oBAAA,CAAA,CAAA;AACF,gBAAA;AACF,YAAA,CAAA,CAAA;;;AAIA,YAAA,MAAMG,wBAAAA,GAA2BpF,MAAM,CAAC,iBAAA,CAAkB,CAACoE,mBAAmB;AAE9E,YAAA,MAAMiB,kBAAAA,GAAqBD,wBAAAA,GACvB3B,aAAAA,CAAQD,sBAAAA,EAAwB4B,wBAAAA,CAAAA,GAChC5B,sBAAAA;;YAGJ,MAAM8B,eAAAA,GAAkB5E,KAAKC,IAAI,CAC/B,IAAI,CAACF,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;;YAGF,MAAMQ,EAAAA,CAAGuE,UAAU,CAACD,eAAAA,CAAAA;AACpB,YAAA,MAAMtE,EAAAA,CAAGwE,SAAS,CAACF,eAAAA,EAAiBD,kBAAAA,EAAoB;gBAAEI,MAAAA,EAAQ;AAAE,aAAA,CAAA;AACtE,QAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"documentation.js","sources":["../../../server/src/services/documentation.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { produce } from 'immer';\nimport type { Core } from '@strapi/types';\n\nimport { builApiEndpointPath, buildComponentSchema } from './helpers';\nimport { getPluginsThatNeedDocumentation } from './utils/get-plugins-that-need-documentation';\nimport { getService } from '../utils';\n\nimport type { Config, PluginConfig } from '../types';\n\nexport type Version = {\n version: string;\n generatedDate: string;\n url: string;\n};\n\nexport type DocumentationService = ReturnType<typeof createService>;\n\nconst createService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = strapi.config.get('plugin::documentation') as PluginConfig;\n const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(config);\n const overrideService = getService('override');\n\n return {\n getDocumentationVersion() {\n return config.info.version;\n },\n\n getFullDocumentationPath() {\n // In production, documentation files live under dist/src/extensions/\n // after the build step. Use dist.extensions for reading.\n const extensionsDir =\n strapi.config.environment === 'production'\n ? strapi.dirs.dist.extensions\n : strapi.dirs.app.extensions;\n\n return path.join(extensionsDir, 'documentation', 'documentation');\n },\n\n getDocumentationVersions(): Version[] {\n return fs\n .readdirSync(this.getFullDocumentationPath())\n .map((version) => {\n try {\n const filePath = path.resolve(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n\n const doc = JSON.parse(fs.readFileSync(filePath).toString());\n\n const generatedDate = doc.info['x-generation-date'];\n\n return { version, generatedDate, url: '' };\n } catch (err) {\n return null;\n }\n })\n .filter((x) => x) as Version[];\n },\n\n /**\n * Returns settings stored in core-store\n */\n async getDocumentationAccess() {\n const { restrictedAccess } = (await strapi.store!({\n environment: '',\n type: 'plugin',\n name: 'documentation',\n key: 'config',\n }).get()) as Config;\n\n return { restrictedAccess };\n },\n\n getApiDocumentationPath(api: { name: string; getter: string }) {\n const isProduction = strapi.config.environment === 'production';\n\n if (api.getter === 'plugin') {\n const extensionsDir = isProduction\n ? strapi.dirs.dist.extensions\n : strapi.dirs.app.extensions;\n return path.join(extensionsDir, api.name, 'documentation');\n }\n\n const apiDir = isProduction ? strapi.dirs.dist.api : strapi.dirs.app.api;\n return path.join(apiDir, api.name, 'documentation');\n },\n\n async deleteDocumentation(version: string) {\n const apis = this.getPluginAndApiInfo();\n for (const api of apis) {\n await fs.remove(path.join(this.getApiDocumentationPath(api), version));\n }\n\n await fs.remove(path.join(this.getFullDocumentationPath(), version));\n },\n\n getPluginAndApiInfo() {\n const pluginsToDocument = pluginsThatNeedDocumentation.map((plugin) => {\n return {\n name: plugin,\n getter: 'plugin',\n ctNames: Object.keys(strapi.plugin(plugin).contentTypes),\n };\n });\n\n const apisToDocument = Object.keys(strapi.apis).map((api) => {\n return {\n name: api,\n getter: 'api',\n ctNames: Object.keys(strapi.api(api).contentTypes),\n };\n });\n\n return [...apisToDocument, ...pluginsToDocument];\n },\n\n /**\n * @description - Creates the Swagger json files\n */\n async generateFullDoc(versionOpt?: string) {\n const version = versionOpt ?? this.getDocumentationVersion();\n\n const apis = this.getPluginAndApiInfo();\n const apisThatNeedGeneratedDocumentation = apis.filter(\n ({ name }) => !overrideService.isEnabled(name)\n );\n\n // Initialize the generated documentation with defaults\n const generatedDocumentation = await produce(config, async (draft) => {\n if (draft.servers?.length === 0) {\n // When no servers found set the defaults\n const serverUrl = strapi.config.get('server.absoluteUrl');\n const apiPath = strapi.config.get('api.rest.prefix');\n draft.servers = [\n {\n url: `${serverUrl}${apiPath}`,\n description: 'Development server',\n },\n ];\n }\n\n if (!draft.components) {\n draft.components = {};\n }\n\n // Set the generated date\n draft.info['x-generation-date'] = new Date().toISOString();\n // Set the plugins that need documentation\n draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;\n\n // Delete the mutateDocumentation key from the config so it doesn't end up in the spec\n delete draft['x-strapi-config'].mutateDocumentation;\n\n // Generate the documentation for each api and update the generatedDocumentation\n for (const api of apisThatNeedGeneratedDocumentation) {\n const newApiPath = builApiEndpointPath(api);\n const generatedSchemas = buildComponentSchema(api);\n\n if (generatedSchemas) {\n draft.components.schemas = { ...draft.components.schemas, ...generatedSchemas };\n }\n\n if (newApiPath) {\n draft.paths = { ...draft.paths, ...newApiPath };\n }\n }\n\n // When overrides are present update the generatedDocumentation\n if (overrideService.registeredOverrides.length > 0) {\n overrideService.registeredOverrides.forEach((override: Partial<PluginConfig>) => {\n // Only run the overrrides when no override version is provided,\n // or when the generated documentation version matches the override version\n if (!override?.info?.version || override.info.version === version) {\n if (override.tags) {\n // Merge override tags with the generated tags\n draft.tags = draft.tags || [];\n draft.tags.push(...override.tags);\n }\n\n if (override.paths) {\n // Merge override paths with the generated paths\n // The override will add a new path or replace the value of an existing path\n draft.paths = { ...draft.paths, ...override.paths };\n }\n\n if (override.components) {\n const keys = Object.keys(override.components) as Array<\n keyof typeof override.components\n >;\n\n keys.forEach((overrideKey) => {\n draft.components = draft.components || {};\n\n const overrideValue = override.components?.[overrideKey];\n const originalValue = draft.components?.[overrideKey];\n\n Object.assign(draft.components, {\n [overrideKey]: {\n ...originalValue,\n ...overrideValue,\n },\n });\n });\n }\n }\n });\n }\n });\n\n // Escape hatch, allow the user to provide a mutateDocumentation function that can alter any part of\n // the generated documentation before it is written to the file system\n const userMutatesDocumentation = config['x-strapi-config'].mutateDocumentation;\n\n const finalDocumentation = userMutatesDocumentation\n ? produce(generatedDocumentation, userMutatesDocumentation)\n : generatedDocumentation;\n\n // Get the file path for the final documentation\n const fullDocJsonPath = path.join(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n // Write the documentation to the file system\n await fs.ensureFile(fullDocJsonPath);\n await fs.writeJson(fullDocJsonPath, finalDocumentation, { spaces: 2 });\n },\n };\n};\n\nexport default createService;\n"],"names":["createService","strapi","config","get","pluginsThatNeedDocumentation","getPluginsThatNeedDocumentation","overrideService","getService","getDocumentationVersion","info","version","getFullDocumentationPath","extensionsDir","environment","dirs","dist","extensions","app","path","join","getDocumentationVersions","fs","readdirSync","map","filePath","resolve","doc","JSON","parse","readFileSync","toString","generatedDate","url","err","filter","x","getDocumentationAccess","restrictedAccess","store","type","name","key","getApiDocumentationPath","api","isProduction","getter","apiDir","deleteDocumentation","apis","getPluginAndApiInfo","remove","pluginsToDocument","plugin","ctNames","Object","keys","contentTypes","apisToDocument","generateFullDoc","versionOpt","apisThatNeedGeneratedDocumentation","isEnabled","generatedDocumentation","produce","draft","servers","length","serverUrl","apiPath","description","components","Date","toISOString","plugins","mutateDocumentation","newApiPath","builApiEndpointPath","generatedSchemas","buildComponentSchema","schemas","paths","registeredOverrides","forEach","override","tags","push","overrideKey","overrideValue","originalValue","assign","userMutatesDocumentation","finalDocumentation","fullDocJsonPath","ensureFile","writeJson","spaces"],"mappings":";;;;;;;;;;AAmBA,MAAMA,aAAAA,GAAgB,CAAC,EAAEC,MAAM,EAA2B,GAAA;AACxD,IAAA,MAAMC,MAAAA,GAASD,MAAAA,CAAOC,MAAM,CAACC,GAAG,CAAC,uBAAA,CAAA;AACjC,IAAA,MAAMC,+BAA+BC,+DAAAA,CAAgCH,MAAAA,CAAAA;AACrE,IAAA,MAAMI,kBAAkBC,gBAAAA,CAAW,UAAA,CAAA;IAEnC,OAAO;AACLC,QAAAA,uBAAAA,CAAAA,GAAAA;YACE,OAAON,MAAAA,CAAOO,IAAI,CAACC,OAAO;AAC5B,QAAA,CAAA;AAEAC,QAAAA,wBAAAA,CAAAA,GAAAA;;;AAGE,YAAA,MAAMC,gBACJX,MAAAA,CAAOC,MAAM,CAACW,WAAW,KAAK,eAC1BZ,MAAAA,CAAOa,IAAI,CAACC,IAAI,CAACC,UAAU,GAC3Bf,MAAAA,CAAOa,IAAI,CAACG,GAAG,CAACD,UAAU;AAEhC,YAAA,OAAOE,IAAAA,CAAKC,IAAI,CAACP,aAAAA,EAAe,eAAA,EAAiB,eAAA,CAAA;AACnD,QAAA,CAAA;AAEAQ,QAAAA,wBAAAA,CAAAA,GAAAA;YACE,OAAOC,EAAAA,CACJC,WAAW,CAAC,IAAI,CAACX,wBAAwB,EAAA,CAAA,CACzCY,GAAG,CAAC,CAACb,OAAAA,GAAAA;gBACJ,IAAI;oBACF,MAAMc,QAAAA,GAAWN,KAAKO,OAAO,CAC3B,IAAI,CAACd,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;oBAGF,MA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A,CAAA;AACtE,QAAA;AACF,KAAA;AACF;;;;"}
@@ -15,7 +15,10 @@ const createService = ({ strapi })=>{
15
15
  return config.info.version;
16
16
  },
17
17
  getFullDocumentationPath () {
18
- return path.join(strapi.dirs.app.extensions, 'documentation', 'documentation');
18
+ // In production, documentation files live under dist/src/extensions/
19
+ // after the build step. Use dist.extensions for reading.
20
+ const extensionsDir = strapi.config.environment === 'production' ? strapi.dirs.dist.extensions : strapi.dirs.app.extensions;
21
+ return path.join(extensionsDir, 'documentation', 'documentation');
19
22
  },
20
23
  getDocumentationVersions () {
21
24
  return fs.readdirSync(this.getFullDocumentationPath()).map((version)=>{
@@ -47,10 +50,13 @@ const createService = ({ strapi })=>{
47
50
  };
48
51
  },
49
52
  getApiDocumentationPath (api) {
53
+ const isProduction = strapi.config.environment === 'production';
50
54
  if (api.getter === 'plugin') {
51
- return path.join(strapi.dirs.app.extensions, api.name, 'documentation');
55
+ const extensionsDir = isProduction ? strapi.dirs.dist.extensions : strapi.dirs.app.extensions;
56
+ return path.join(extensionsDir, api.name, 'documentation');
52
57
  }
53
- return path.join(strapi.dirs.app.api, api.name, 'documentation');
58
+ const apiDir = isProduction ? strapi.dirs.dist.api : strapi.dirs.app.api;
59
+ return path.join(apiDir, api.name, 'documentation');
54
60
  },
55
61
  async deleteDocumentation (version) {
56
62
  const apis = this.getPluginAndApiInfo();
@@ -1 +1 @@
1
- {"version":3,"file":"documentation.mjs","sources":["../../../server/src/services/documentation.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { produce } from 'immer';\nimport type { Core } from '@strapi/types';\n\nimport { builApiEndpointPath, buildComponentSchema } from './helpers';\nimport { getPluginsThatNeedDocumentation } from './utils/get-plugins-that-need-documentation';\nimport { getService } from '../utils';\n\nimport type { Config, PluginConfig } from '../types';\n\nexport type Version = {\n version: string;\n generatedDate: string;\n url: string;\n};\n\nexport type DocumentationService = ReturnType<typeof createService>;\n\nconst createService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = strapi.config.get('plugin::documentation') as PluginConfig;\n const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(config);\n const overrideService = getService('override');\n\n return {\n getDocumentationVersion() {\n return config.info.version;\n },\n\n getFullDocumentationPath() {\n return path.join(strapi.dirs.app.extensions, 'documentation', 'documentation');\n },\n\n getDocumentationVersions(): Version[] {\n return fs\n .readdirSync(this.getFullDocumentationPath())\n .map((version) => {\n try {\n const filePath = path.resolve(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n\n const doc = JSON.parse(fs.readFileSync(filePath).toString());\n\n const generatedDate = doc.info['x-generation-date'];\n\n return { version, generatedDate, url: '' };\n } catch (err) {\n return null;\n }\n })\n .filter((x) => x) as Version[];\n },\n\n /**\n * Returns settings stored in core-store\n */\n async getDocumentationAccess() {\n const { restrictedAccess } = (await strapi.store!({\n environment: '',\n type: 'plugin',\n name: 'documentation',\n key: 'config',\n }).get()) as Config;\n\n return { restrictedAccess };\n },\n\n getApiDocumentationPath(api: { name: string; getter: string }) {\n if (api.getter === 'plugin') {\n return path.join(strapi.dirs.app.extensions, api.name, 'documentation');\n }\n\n return path.join(strapi.dirs.app.api, api.name, 'documentation');\n },\n\n async deleteDocumentation(version: string) {\n const apis = this.getPluginAndApiInfo();\n for (const api of apis) {\n await fs.remove(path.join(this.getApiDocumentationPath(api), version));\n }\n\n await fs.remove(path.join(this.getFullDocumentationPath(), version));\n },\n\n getPluginAndApiInfo() {\n const pluginsToDocument = pluginsThatNeedDocumentation.map((plugin) => {\n return {\n name: plugin,\n getter: 'plugin',\n ctNames: Object.keys(strapi.plugin(plugin).contentTypes),\n };\n });\n\n const apisToDocument = Object.keys(strapi.apis).map((api) => {\n return {\n name: api,\n getter: 'api',\n ctNames: Object.keys(strapi.api(api).contentTypes),\n };\n });\n\n return [...apisToDocument, ...pluginsToDocument];\n },\n\n /**\n * @description - Creates the Swagger json files\n */\n async generateFullDoc(versionOpt?: string) {\n const version = versionOpt ?? this.getDocumentationVersion();\n\n const apis = this.getPluginAndApiInfo();\n const apisThatNeedGeneratedDocumentation = apis.filter(\n ({ name }) => !overrideService.isEnabled(name)\n );\n\n // Initialize the generated documentation with defaults\n const generatedDocumentation = await produce(config, async (draft) => {\n if (draft.servers?.length === 0) {\n // When no servers found set the defaults\n const serverUrl = strapi.config.get('server.absoluteUrl');\n const apiPath = strapi.config.get('api.rest.prefix');\n draft.servers = [\n {\n url: `${serverUrl}${apiPath}`,\n description: 'Development server',\n },\n ];\n }\n\n if (!draft.components) {\n draft.components = {};\n }\n\n // Set the generated date\n draft.info['x-generation-date'] = new Date().toISOString();\n // Set the plugins that need documentation\n draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;\n\n // Delete the mutateDocumentation key from the config so it doesn't end up in the spec\n delete draft['x-strapi-config'].mutateDocumentation;\n\n // Generate the documentation for each api and update the generatedDocumentation\n for (const api of apisThatNeedGeneratedDocumentation) {\n const newApiPath = builApiEndpointPath(api);\n const generatedSchemas = buildComponentSchema(api);\n\n if (generatedSchemas) {\n draft.components.schemas = { ...draft.components.schemas, ...generatedSchemas };\n }\n\n if (newApiPath) {\n draft.paths = { ...draft.paths, ...newApiPath };\n }\n }\n\n // When overrides are present update the generatedDocumentation\n if (overrideService.registeredOverrides.length > 0) {\n overrideService.registeredOverrides.forEach((override: Partial<PluginConfig>) => {\n // Only run the overrrides when no override version is provided,\n // or when the generated documentation version matches the override version\n if (!override?.info?.version || override.info.version === version) {\n if (override.tags) {\n // Merge override tags with the generated tags\n draft.tags = draft.tags || [];\n draft.tags.push(...override.tags);\n }\n\n if (override.paths) {\n // Merge override paths with the generated paths\n // The override will add a new path or replace the value of an existing path\n draft.paths = { ...draft.paths, ...override.paths };\n }\n\n if (override.components) {\n const keys = Object.keys(override.components) as Array<\n keyof typeof override.components\n >;\n\n keys.forEach((overrideKey) => {\n draft.components = draft.components || {};\n\n const overrideValue = override.components?.[overrideKey];\n const originalValue = draft.components?.[overrideKey];\n\n Object.assign(draft.components, {\n [overrideKey]: {\n ...originalValue,\n ...overrideValue,\n },\n });\n });\n }\n }\n });\n }\n });\n\n // Escape hatch, allow the user to provide a mutateDocumentation function that can alter any part of\n // the generated documentation before it is written to the file system\n const userMutatesDocumentation = config['x-strapi-config'].mutateDocumentation;\n\n const finalDocumentation = userMutatesDocumentation\n ? produce(generatedDocumentation, userMutatesDocumentation)\n : generatedDocumentation;\n\n // Get the file path for the final documentation\n const fullDocJsonPath = path.join(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n // Write the documentation to the file system\n await fs.ensureFile(fullDocJsonPath);\n await fs.writeJson(fullDocJsonPath, finalDocumentation, { spaces: 2 });\n },\n };\n};\n\nexport default createService;\n"],"names":["createService","strapi","config","get","pluginsThatNeedDocumentation","getPluginsThatNeedDocumentation","overrideService","getService","getDocumentationVersion","info","version","getFullDocumentationPath","path","join","dirs","app","extensions","getDocumentationVersions","fs","readdirSync","map","filePath","resolve","doc","JSON","parse","readFileSync","toString","generatedDate","url","err","filter","x","getDocumentationAccess","restrictedAccess","store","environment","type","name","key","getApiDocumentationPath","api","getter","deleteDocumentation","apis","getPluginAndApiInfo","remove","pluginsToDocument","plugin","ctNames","Object","keys","contentTypes","apisToDocument","generateFullDoc","versionOpt","apisThatNeedGeneratedDocumentation","isEnabled","generatedDocumentation","produce","draft","servers","length","serverUrl","apiPath","description","components","Date","toISOString","plugins","mutateDocumentation","newApiPath","builApiEndpointPath","generatedSchemas","buildComponentSchema","schemas","paths","registeredOverrides","forEach","override","tags","push","overrideKey","overrideValue","originalValue","assign","userMutatesDocumentation","finalDocumentation","fullDocJsonPath","ensureFile","writeJson","spaces"],"mappings":";;;;;;;;AAmBA,MAAMA,aAAAA,GAAgB,CAAC,EAAEC,MAAM,EAA2B,GAAA;AACxD,IAAA,MAAMC,MAAAA,GAASD,MAAAA,CAAOC,MAAM,CAACC,GAAG,CAAC,uBAAA,CAAA;AACjC,IAAA,MAAMC,+BAA+BC,+BAAAA,CAAgCH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,EAAwB4B,wBAAAA,CAAAA,GAChC5B,sBAAAA;;YAGJ,MAAM8B,eAAAA,GAAkB5E,KAAKC,IAAI,CAC/B,IAAI,CAACF,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;;YAGF,MAAMQ,EAAAA,CAAGuE,UAAU,CAACD,eAAAA,CAAAA;AACpB,YAAA,MAAMtE,EAAAA,CAAGwE,SAAS,CAACF,eAAAA,EAAiBD,kBAAAA,EAAoB;gBAAEI,MAAAA,EAAQ;AAAE,aAAA,CAAA;AACtE,QAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"documentation.mjs","sources":["../../../server/src/services/documentation.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs-extra';\nimport { produce } from 'immer';\nimport type { Core } from '@strapi/types';\n\nimport { builApiEndpointPath, buildComponentSchema } from './helpers';\nimport { getPluginsThatNeedDocumentation } from './utils/get-plugins-that-need-documentation';\nimport { getService } from '../utils';\n\nimport type { Config, PluginConfig } from '../types';\n\nexport type Version = {\n version: string;\n generatedDate: string;\n url: string;\n};\n\nexport type DocumentationService = ReturnType<typeof createService>;\n\nconst createService = ({ strapi }: { strapi: Core.Strapi }) => {\n const config = strapi.config.get('plugin::documentation') as PluginConfig;\n const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(config);\n const overrideService = getService('override');\n\n return {\n getDocumentationVersion() {\n return config.info.version;\n },\n\n getFullDocumentationPath() {\n // In production, documentation files live under dist/src/extensions/\n // after the build step. Use dist.extensions for reading.\n const extensionsDir =\n strapi.config.environment === 'production'\n ? strapi.dirs.dist.extensions\n : strapi.dirs.app.extensions;\n\n return path.join(extensionsDir, 'documentation', 'documentation');\n },\n\n getDocumentationVersions(): Version[] {\n return fs\n .readdirSync(this.getFullDocumentationPath())\n .map((version) => {\n try {\n const filePath = path.resolve(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n\n const doc = JSON.parse(fs.readFileSync(filePath).toString());\n\n const generatedDate = doc.info['x-generation-date'];\n\n return { version, generatedDate, url: '' };\n } catch (err) {\n return null;\n }\n })\n .filter((x) => x) as Version[];\n },\n\n /**\n * Returns settings stored in core-store\n */\n async getDocumentationAccess() {\n const { restrictedAccess } = (await strapi.store!({\n environment: '',\n type: 'plugin',\n name: 'documentation',\n key: 'config',\n }).get()) as Config;\n\n return { restrictedAccess };\n },\n\n getApiDocumentationPath(api: { name: string; getter: string }) {\n const isProduction = strapi.config.environment === 'production';\n\n if (api.getter === 'plugin') {\n const extensionsDir = isProduction\n ? strapi.dirs.dist.extensions\n : strapi.dirs.app.extensions;\n return path.join(extensionsDir, api.name, 'documentation');\n }\n\n const apiDir = isProduction ? strapi.dirs.dist.api : strapi.dirs.app.api;\n return path.join(apiDir, api.name, 'documentation');\n },\n\n async deleteDocumentation(version: string) {\n const apis = this.getPluginAndApiInfo();\n for (const api of apis) {\n await fs.remove(path.join(this.getApiDocumentationPath(api), version));\n }\n\n await fs.remove(path.join(this.getFullDocumentationPath(), version));\n },\n\n getPluginAndApiInfo() {\n const pluginsToDocument = pluginsThatNeedDocumentation.map((plugin) => {\n return {\n name: plugin,\n getter: 'plugin',\n ctNames: Object.keys(strapi.plugin(plugin).contentTypes),\n };\n });\n\n const apisToDocument = Object.keys(strapi.apis).map((api) => {\n return {\n name: api,\n getter: 'api',\n ctNames: Object.keys(strapi.api(api).contentTypes),\n };\n });\n\n return [...apisToDocument, ...pluginsToDocument];\n },\n\n /**\n * @description - Creates the Swagger json files\n */\n async generateFullDoc(versionOpt?: string) {\n const version = versionOpt ?? this.getDocumentationVersion();\n\n const apis = this.getPluginAndApiInfo();\n const apisThatNeedGeneratedDocumentation = apis.filter(\n ({ name }) => !overrideService.isEnabled(name)\n );\n\n // Initialize the generated documentation with defaults\n const generatedDocumentation = await produce(config, async (draft) => {\n if (draft.servers?.length === 0) {\n // When no servers found set the defaults\n const serverUrl = strapi.config.get('server.absoluteUrl');\n const apiPath = strapi.config.get('api.rest.prefix');\n draft.servers = [\n {\n url: `${serverUrl}${apiPath}`,\n description: 'Development server',\n },\n ];\n }\n\n if (!draft.components) {\n draft.components = {};\n }\n\n // Set the generated date\n draft.info['x-generation-date'] = new Date().toISOString();\n // Set the plugins that need documentation\n draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;\n\n // Delete the mutateDocumentation key from the config so it doesn't end up in the spec\n delete draft['x-strapi-config'].mutateDocumentation;\n\n // Generate the documentation for each api and update the generatedDocumentation\n for (const api of apisThatNeedGeneratedDocumentation) {\n const newApiPath = builApiEndpointPath(api);\n const generatedSchemas = buildComponentSchema(api);\n\n if (generatedSchemas) {\n draft.components.schemas = { ...draft.components.schemas, ...generatedSchemas };\n }\n\n if (newApiPath) {\n draft.paths = { ...draft.paths, ...newApiPath };\n }\n }\n\n // When overrides are present update the generatedDocumentation\n if (overrideService.registeredOverrides.length > 0) {\n overrideService.registeredOverrides.forEach((override: Partial<PluginConfig>) => {\n // Only run the overrrides when no override version is provided,\n // or when the generated documentation version matches the override version\n if (!override?.info?.version || override.info.version === version) {\n if (override.tags) {\n // Merge override tags with the generated tags\n draft.tags = draft.tags || [];\n draft.tags.push(...override.tags);\n }\n\n if (override.paths) {\n // Merge override paths with the generated paths\n // The override will add a new path or replace the value of an existing path\n draft.paths = { ...draft.paths, ...override.paths };\n }\n\n if (override.components) {\n const keys = Object.keys(override.components) as Array<\n keyof typeof override.components\n >;\n\n keys.forEach((overrideKey) => {\n draft.components = draft.components || {};\n\n const overrideValue = override.components?.[overrideKey];\n const originalValue = draft.components?.[overrideKey];\n\n Object.assign(draft.components, {\n [overrideKey]: {\n ...originalValue,\n ...overrideValue,\n },\n });\n });\n }\n }\n });\n }\n });\n\n // Escape hatch, allow the user to provide a mutateDocumentation function that can alter any part of\n // the generated documentation before it is written to the file system\n const userMutatesDocumentation = config['x-strapi-config'].mutateDocumentation;\n\n const finalDocumentation = userMutatesDocumentation\n ? produce(generatedDocumentation, userMutatesDocumentation)\n : generatedDocumentation;\n\n // Get the file path for the final documentation\n const fullDocJsonPath = path.join(\n this.getFullDocumentationPath(),\n version,\n 'full_documentation.json'\n );\n // Write the documentation to the file system\n await fs.ensureFile(fullDocJsonPath);\n await fs.writeJson(fullDocJsonPath, finalDocumentation, { spaces: 2 });\n },\n };\n};\n\nexport default createService;\n"],"names":["createService","strapi","config","get","pluginsThatNeedDocumentation","getPluginsThatNeedDocumentation","overrideService","getService","getDocumentationVersion","info","version","getFullDocumentationPath","extensionsDir","environment","dirs","dist","extensions","app","path","join","getDocumentationVersions","fs","readdirSync","map","filePath","resolve","doc","JSON","parse","readFileSync","toString","generatedDate","url","err","filter","x","getDocumentationAccess","restrictedAccess","store","type","name","key","getApiDocumentationPath","api","isProduction","getter","apiDir","deleteDocumentation","apis","getPluginAndApiInfo","remove","pluginsToDocument","plugin","ctNames","Object","keys","contentTypes","apisToDocument","generateFullDoc","versionOpt","apisThatNeedGeneratedDocumentation","isEnabled","generatedDocumentation","produce","draft","servers","length","serverUrl","apiPath","description","components","Date","toISOString","plugins","mutateDocumentation","newApiPath","builApiEndpointPath","generatedSchemas","buildComponentSchema","schemas","paths","registeredOverrides","forEach","override","tags","push","overrideKey","overrideValue","originalValue","assign","userMutatesDocumentation","finalDocumentation","fullDocJsonPath","ensureFile","writeJson","spaces"],"mappings":";;;;;;;;AAmBA,MAAMA,aAAAA,GAAgB,CAAC,EAAEC,MAAM,EAA2B,GAAA;AACxD,IAAA,MAAMC,MAAAA,GAASD,MAAAA,CAAOC,MAAM,CAACC,GAAG,CAAC,uBAAA,CAAA;AACjC,IAAA,MAAMC,+BAA+BC,+BAAAA,CAAgCH,MAAAA,CAAAA;AACrE,IAAA,MAAMI,kBAAkBC,UAAAA,CAAW,UAAA,CAAA;IAEnC,OAAO;AACLC,QAAAA,uBAAAA,CAAAA,GAAAA;YACE,OAAON,MAAAA,CAAOO,IAAI,CAACC,OAAO;AAC5B,QAAA,CAAA;AAEAC,QAAAA,wBAAAA,CAAAA,GAAAA;;;AAGE,YAAA,MAAMC,g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AA,CAAA,CAAA;AACF,gBAAA;AACF,YAAA,CAAA,CAAA;;;AAIA,YAAA,MAAMG,wBAAAA,GAA2BxF,MAAM,CAAC,iBAAA,CAAkB,CAACwE,mBAAmB;AAE9E,YAAA,MAAMiB,kBAAAA,GAAqBD,wBAAAA,GACvB3B,OAAAA,CAAQD,sBAAAA,EAAwB4B,wBAAAA,CAAAA,GAChC5B,sBAAAA;;YAGJ,MAAM8B,eAAAA,GAAkB1E,KAAKC,IAAI,CAC/B,IAAI,CAACR,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;;YAGF,MAAMW,EAAAA,CAAGwE,UAAU,CAACD,eAAAA,CAAAA;AACpB,YAAA,MAAMvE,EAAAA,CAAGyE,SAAS,CAACF,eAAAA,EAAiBD,kBAAAA,EAAoB;gBAAEI,MAAAA,EAAQ;AAAE,aAAA,CAAA;AACtE,QAAA;AACF,KAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"documentation.d.ts","sourceRoot":"","sources":["../../../../server/src/controllers/documentation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;;kBAwBL,IAAI,OAAO;eAkBd,IAAI,OAAO,QAAQ,IAAI,IAAI;mBAgEvB,IAAI,OAAO,QAAQ,IAAI,IAAI;eA4C/B,IAAI,OAAO;uBAwBH,IAAI,OAAO;mBAwBf,IAAI,OAAO;wBAwBN,IAAI,OAAO;;AAvMvC,wBAwNE"}
1
+ {"version":3,"file":"documentation.d.ts","sourceRoot":"","sources":["../../../../server/src/controllers/documentation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;;kBAwBL,IAAI,OAAO;eAkBd,IAAI,OAAO,QAAQ,IAAI,IAAI;mBA4DvB,IAAI,OAAO,QAAQ,IAAI,IAAI;eA4C/B,IAAI,OAAO;uBAwBH,IAAI,OAAO;mBAwBf,IAAI,OAAO;wBAwBN,IAAI,OAAO;;AAnMvC,wBAoNE"}
@@ -1 +1 @@
1
- {"version":3,"file":"documentation.d.ts","sourceRoot":"","sources":["../../../../server/src/services/documentation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAQ1C,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpE,QAAA,MAAM,aAAa,eAAgB;IAAE,MAAM,EAAE,KAAK,MAAM,CAAA;CAAE;;;gCAc1B,OAAO,EAAE;IAuBrC;;OAEG;;;;iCAY0B;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;iCAQ1B,MAAM;;;;;;IA6BzC;;OAEG;iCACgC,MAAM;CA6G5C,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"documentation.d.ts","sourceRoot":"","sources":["../../../../server/src/services/documentation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAQ1C,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpE,QAAA,MAAM,aAAa,eAAgB;IAAE,MAAM,EAAE,KAAK,MAAM,CAAA;CAAE;;;gCAqB1B,OAAO,EAAE;IAuBrC;;OAEG;;;;iCAY0B;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;iCAc1B,MAAM;;;;;;IA6BzC;;OAEG;iCACgC,MAAM;CA6G5C,CAAC;AAEF,eAAe,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-documentation",
3
- "version": "5.41.1",
3
+ "version": "5.42.0",
4
4
  "description": "Create an OpenAPI Document and visualize your API with SWAGGER UI.",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -63,10 +63,10 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@reduxjs/toolkit": "1.9.7",
66
- "@strapi/admin": "5.41.1",
66
+ "@strapi/admin": "5.42.0",
67
67
  "@strapi/design-system": "2.2.0",
68
68
  "@strapi/icons": "2.2.0",
69
- "@strapi/utils": "5.41.1",
69
+ "@strapi/utils": "5.42.0",
70
70
  "bcryptjs": "2.4.3",
71
71
  "cheerio": "^1.0.0",
72
72
  "formik": "2.4.5",
@@ -74,7 +74,7 @@
74
74
  "immer": "9.0.21",
75
75
  "koa-static": "^5.0.0",
76
76
  "lodash": "4.17.23",
77
- "path-to-regexp": "8.2.0",
77
+ "path-to-regexp": "8.4.1",
78
78
  "react-intl": "6.6.2",
79
79
  "swagger-ui-dist": "4.19.0",
80
80
  "yaml": "1.10.2",
@@ -82,9 +82,9 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@apidevtools/swagger-parser": "^10.1.0",
85
- "@strapi/admin-test-utils": "5.41.1",
86
- "@strapi/strapi": "5.41.1",
87
- "@strapi/types": "5.41.1",
85
+ "@strapi/admin-test-utils": "5.42.0",
86
+ "@strapi/strapi": "5.42.0",
87
+ "@strapi/types": "5.42.0",
88
88
  "@testing-library/react": "16.3.0",
89
89
  "@testing-library/user-event": "14.6.1",
90
90
  "@types/fs-extra": "11.0.4",