@strapi/plugin-documentation 5.51.0 → 5.51.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/README.md
CHANGED
|
@@ -82,7 +82,7 @@ Overriding the `full_documentation.json` is a bad idea since it will be regenera
|
|
|
82
82
|
|
|
83
83
|
**_NOTE 2_**
|
|
84
84
|
|
|
85
|
-
You can modify the `tags`, `paths`, and `components` keys on the generated documentation by providing replacement values. You can see how the API is used in the users-permissions plugin: `packages/plugins/users-permissions/server/register.js`
|
|
85
|
+
You can modify the `tags`, `paths`, and `components` keys on the generated documentation by providing replacement values. You can see how the API is used in the users-permissions plugin: `packages/plugins/users-permissions/server/src/register.js`
|
|
86
86
|
|
|
87
87
|
### FAQ
|
|
88
88
|
|
|
@@ -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 // 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,OAA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,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,GAA2BxF,MAAM,CAAC,iBAAA,CAAkB,CAACwE,mBAAmB;AAE9E,YAAA,MAAMiB,kBAAAA,GAAqBD,wBAAAA,GACvB3B,aAAAA,CAAQD,sBAAAA,EAAwB4B,wBAAAA,CAAAA,GAChC5B,sBAAAA;;YAGJ,MAAM8B,eAAAA,GAAkB1E,sBAAKC,IAAI,CAC/B,IAAI,CAACR,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;;YAGF,MAAMW,mBAAAA,CAAGwE,UAAU,CAACD,eAAAA,CAAAA;AACpB,YAAA,MAAMvE,mBAAAA,CAAGyE,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 {\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","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,EAAE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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,GAA2BvF,MAAM,CAAC,iBAAA,CAAkB,CAACuE,mBAAmB;AAE9E,YAAA,MAAMiB,kBAAAA,GAAqBD,wBAAAA,GACvB3B,aAAAA,CAAQD,sBAAAA,EAAwB4B,wBAAAA,CAAAA,GAChC5B,sBAAAA;;YAGJ,MAAM8B,eAAAA,GAAkBzE,sBAAKC,IAAI,CAC/B,IAAI,CAACR,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;;YAGF,MAAMW,mBAAAA,CAAGuE,UAAU,CAACD,eAAAA,CAAAA;AACpB,YAAA,MAAMtE,mBAAAA,CAAGwE,SAAS,CAACF,eAAAA,EAAiBD,kBAAAA,EAAoB;gBAAEI,MAAAA,EAAQ;AAAE,aAAA,CAAA;AACtE,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -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 // 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,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,MAAMgB,GAAAA,GAAMC,KAAKC,KAAK,CAACP,GAAGQ,YAAY,CAACL,UAAUM,QAAQ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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 {\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","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,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,OAA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CAAAA;AACpB,YAAA,MAAMtE,EAAAA,CAAGwE,SAAS,CAACF,eAAAA,EAAiBD,kBAAAA,EAAoB;gBAAEI,MAAAA,EAAQ;AAAE,aAAA,CAAA;AACtE,QAAA;AACF,KAAA;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-documentation",
|
|
3
|
-
"version": "5.51.
|
|
3
|
+
"version": "5.51.2",
|
|
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.51.
|
|
66
|
+
"@strapi/admin": "5.51.2",
|
|
67
67
|
"@strapi/design-system": "2.2.3",
|
|
68
68
|
"@strapi/icons": "2.2.3",
|
|
69
|
-
"@strapi/utils": "5.51.
|
|
69
|
+
"@strapi/utils": "5.51.2",
|
|
70
70
|
"bcryptjs": "2.4.3",
|
|
71
71
|
"cheerio": "^1.2.0",
|
|
72
72
|
"formik": "2.4.9",
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
85
|
-
"@strapi/admin-test-utils": "5.51.
|
|
86
|
-
"@strapi/strapi": "5.51.
|
|
87
|
-
"@strapi/types": "5.51.
|
|
85
|
+
"@strapi/admin-test-utils": "5.51.2",
|
|
86
|
+
"@strapi/strapi": "5.51.2",
|
|
87
|
+
"@strapi/types": "5.51.2",
|
|
88
88
|
"@testing-library/dom": "10.4.1",
|
|
89
89
|
"@testing-library/jest-dom": "6.9.1",
|
|
90
90
|
"@testing-library/react": "16.3.2",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"openapi-types": "12.1.3",
|
|
103
103
|
"react": "18.3.1",
|
|
104
104
|
"react-dom": "18.3.1",
|
|
105
|
-
"react-router-dom": "6.30.
|
|
105
|
+
"react-router-dom": "6.30.4",
|
|
106
106
|
"styled-components": "6.4.1"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|