@strapi/plugin-documentation 5.56.0 → 5.57.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.
Files changed (27) hide show
  1. package/dist/server/services/documentation.js +4 -1
  2. package/dist/server/services/documentation.js.map +1 -1
  3. package/dist/server/services/documentation.mjs +5 -2
  4. package/dist/server/services/documentation.mjs.map +1 -1
  5. package/dist/server/services/helpers/build-component-schema.js +19 -4
  6. package/dist/server/services/helpers/build-component-schema.js.map +1 -1
  7. package/dist/server/services/helpers/build-component-schema.mjs +16 -4
  8. package/dist/server/services/helpers/build-component-schema.mjs.map +1 -1
  9. package/dist/server/services/helpers/utils/clean-schema-attributes.js +14 -13
  10. package/dist/server/services/helpers/utils/clean-schema-attributes.js.map +1 -1
  11. package/dist/server/services/helpers/utils/clean-schema-attributes.mjs +14 -13
  12. package/dist/server/services/helpers/utils/clean-schema-attributes.mjs.map +1 -1
  13. package/dist/server/services/helpers/utils/loop-content-type-names.js +1 -0
  14. package/dist/server/services/helpers/utils/loop-content-type-names.js.map +1 -1
  15. package/dist/server/services/helpers/utils/loop-content-type-names.mjs +1 -0
  16. package/dist/server/services/helpers/utils/loop-content-type-names.mjs.map +1 -1
  17. package/dist/server/src/services/documentation.d.ts.map +1 -1
  18. package/dist/server/src/services/helpers/build-component-schema.d.ts +3 -1
  19. package/dist/server/src/services/helpers/build-component-schema.d.ts.map +1 -1
  20. package/dist/server/src/services/helpers/index.d.ts +2 -2
  21. package/dist/server/src/services/helpers/index.d.ts.map +1 -1
  22. package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts +2 -2
  23. package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts.map +1 -1
  24. package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts.map +1 -1
  25. package/dist/server/src/types.d.ts +1 -0
  26. package/dist/server/src/types.d.ts.map +1 -1
  27. package/package.json +6 -6
@@ -120,10 +120,13 @@ const createService = ({ strapi })=>{
120
120
  draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;
121
121
  // Delete the mutateDocumentation key from the config so it doesn't end up in the spec
122
122
  delete draft['x-strapi-config'].mutateDocumentation;
123
+ const relationTargetSchemaNames = new Map(apisThatNeedGeneratedDocumentation.flatMap((api)=>[
124
+ ...buildComponentSchema.getRelationTargetSchemaNames(api)
125
+ ]));
123
126
  // Generate the documentation for each api and update the generatedDocumentation
124
127
  for (const api of apisThatNeedGeneratedDocumentation){
125
128
  const newApiPath = buildApiEndpointPath(api);
126
- const generatedSchemas = buildComponentSchema(api);
129
+ const generatedSchemas = buildComponentSchema.default(api, relationTargetSchemaNames);
127
130
  if (generatedSchemas) {
128
131
  draft.components.schemas = {
129
132
  ...draft.components.schemas,
@@ -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 {\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,+DAAAA,CAAgCH,MAAAA,CAAAA;AACrE,IAAA,MAAMI,kBAAkBC,gBAAAA,CAAW,UAAA,CAAA;IAEnC,OAAO;AACLC,QAAAA,uBAAAA,CAAAA,GAAAA;YACE,OAAON,M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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
+ {"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, getRelationTargetSchemaNames } 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 const relationTargetSchemaNames = new Map(\n apisThatNeedGeneratedDocumentation.flatMap((api) => [\n ...getRelationTargetSchemaNames(api),\n ])\n );\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, relationTargetSchemaNames);\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","relationTargetSchemaNames","Map","flatMap","getRelationTargetSchemaNames","newApiPath","builApiEndpointPath","generatedSchemas","buildComponentSchema","schemas","paths","registeredOverrides","forEach","override","tags","push","overrideKey","overrideValue","originalValue","assign","userMutatesDocumentation","finalDocumentation","fullDoc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 -2,7 +2,7 @@ import path from 'path';
2
2
  import fs from 'fs-extra';
3
3
  import { produce } from 'immer';
4
4
  import buildApiEndpointPath from './helpers/build-api-endpoint-path.mjs';
5
- import buildComponentSchema from './helpers/build-component-schema.mjs';
5
+ import buildComponentSchema, { getRelationTargetSchemaNames } from './helpers/build-component-schema.mjs';
6
6
  import { getPluginsThatNeedDocumentation } from './utils/get-plugins-that-need-documentation.mjs';
7
7
  import { getService } from '../utils.mjs';
8
8
 
@@ -113,10 +113,13 @@ const createService = ({ strapi })=>{
113
113
  draft['x-strapi-config'].plugins = pluginsThatNeedDocumentation;
114
114
  // Delete the mutateDocumentation key from the config so it doesn't end up in the spec
115
115
  delete draft['x-strapi-config'].mutateDocumentation;
116
+ const relationTargetSchemaNames = new Map(apisThatNeedGeneratedDocumentation.flatMap((api)=>[
117
+ ...getRelationTargetSchemaNames(api)
118
+ ]));
116
119
  // Generate the documentation for each api and update the generatedDocumentation
117
120
  for (const api of apisThatNeedGeneratedDocumentation){
118
121
  const newApiPath = buildApiEndpointPath(api);
119
- const generatedSchemas = buildComponentSchema(api);
122
+ const generatedSchemas = buildComponentSchema(api, relationTargetSchemaNames);
120
123
  if (generatedSchemas) {
121
124
  draft.components.schemas = {
122
125
  ...draft.components.schemas,
@@ -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 {\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":";;;;;;;;AAm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AA,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,GAA2BvF,MAAM,CAAC,iBAAA,CAAkB,CAACuE,mBAAmB;AAE9E,YAAA,MAAMiB,kBAAAA,GAAqBD,wBAAAA,GACvB3B,OAAAA,CAAQD,sBAAAA,EAAwB4B,wBAAAA,CAAAA,GAChC5B,sBAAAA;;YAGJ,MAAM8B,eAAAA,GAAkBzE,KAAKC,IAAI,CAC/B,IAAI,CAACR,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;;YAGF,MAAMW,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, getRelationTargetSchemaNames } 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 const relationTargetSchemaNames = new Map(\n apisThatNeedGeneratedDocumentation.flatMap((api) => [\n ...getRelationTargetSchemaNames(api),\n ])\n );\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, relationTargetSchemaNames);\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","relationTargetSchemaNames","Map","flatMap","getRelationTargetSchemaNames","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,O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AI,CAC/B,IAAI,CAACR,wBAAwB,IAC7BD,OAAAA,EACA,yBAAA,CAAA;;YAGF,MAAMW,EAAAA,CAAG2E,UAAU,CAACD,eAAAA,CAAAA;AACpB,YAAA,MAAM1E,EAAAA,CAAG4E,SAAS,CAACF,eAAAA,EAAiBD,kBAAAA,EAAoB;gBAAEI,MAAAA,EAAQ;AAAE,aAAA,CAAA;AACtE,QAAA;AACF,KAAA;AACF;;;;"}
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var _ = require('lodash');
4
6
  var cleanSchemaAttributes = require('./utils/clean-schema-attributes.js');
5
7
  var loopContentTypeNames = require('./utils/loop-content-type-names.js');
@@ -28,7 +30,7 @@ const getRequiredAttributes = (allAttributes)=>{
28
30
  * @property {object} apiInfo.routeInfo - The routes for the api
29
31
  *
30
32
  * @returns {object} Open API schemas
31
- */ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName })=>{
33
+ */ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName, relationTargetSchemaNames })=>{
32
34
  // Store response and request schemas in an object
33
35
  let strapiComponentSchemas = {};
34
36
  const schemas = {};
@@ -146,6 +148,7 @@ const getRequiredAttributes = (allAttributes)=>{
146
148
  type: 'string'
147
149
  },
148
150
  ...cleanSchemaAttributes(attributes, {
151
+ relationTargetSchemaNames,
149
152
  didAddStrapiComponentsToSchemas
150
153
  })
151
154
  }
@@ -167,12 +170,24 @@ const getRequiredAttributes = (allAttributes)=>{
167
170
  ...strapiComponentSchemas
168
171
  };
169
172
  };
170
- const buildComponentSchema = (api)=>{
173
+ const getRelationTargetSchemaNames = (api)=>{
174
+ const relationTargetSchemaNames = new Map();
175
+ loopContentTypeNames(api, ({ uid, uniqueName })=>{
176
+ relationTargetSchemaNames.set(uid, pascalCase(uniqueName));
177
+ return {};
178
+ });
179
+ return relationTargetSchemaNames;
180
+ };
181
+ const buildComponentSchema = (api, relationTargetSchemaNames = getRelationTargetSchemaNames(api))=>{
171
182
  // A reusable loop for building paths and component schemas
172
183
  // Uses the api param to build a new set of params for each content type
173
184
  // Passes these new params to the function provided
174
- return loopContentTypeNames(api, getAllSchemasForContentType);
185
+ return loopContentTypeNames(api, (apiInfo)=>getAllSchemasForContentType({
186
+ ...apiInfo,
187
+ relationTargetSchemaNames
188
+ }));
175
189
  };
176
190
 
177
- module.exports = buildComponentSchema;
191
+ exports.default = buildComponentSchema;
192
+ exports.getRelationTargetSchemaNames = getRelationTargetSchemaNames;
178
193
  //# sourceMappingURL=build-component-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-component-schema.js","sources":["../../../../server/src/services/helpers/build-component-schema.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { Core, Struct } from '@strapi/types';\n\nimport cleanSchemaAttributes from './utils/clean-schema-attributes';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport pascalCase from './utils/pascal-case';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\nconst getRequiredAttributes = (allAttributes: Struct.SchemaAttributes) => {\n const requiredAttributes: string[] = [];\n\n for (const key in allAttributes) {\n if (allAttributes[key].required) {\n requiredAttributes.push(key);\n }\n }\n\n return requiredAttributes;\n};\n\n/**\n * @description Get all open api schema objects for a given content type\n *\n * @param {object} apiInfo\n * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name\n * @property {object} apiInfo.attributes - Attributes on content type\n * @property {object} apiInfo.routeInfo - The routes for the api\n *\n * @returns {object} Open API schemas\n */\nconst getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }: ApiInfo) => {\n // Store response and request schemas in an object\n let strapiComponentSchemas = {};\n const schemas: OpenAPIV3.ComponentsObject = {};\n const typeName = pascalCase(uniqueName);\n\n // adds a ComponentSchema to the Schemas so it can be used as Ref\n const didAddStrapiComponentsToSchemas = (schemaName: string, schema: OpenAPIV3.SchemaObject) => {\n if (!Object.keys(schema) || !Object.keys(schema.properties!)) return false;\n\n // Add the Strapi components to the schema\n strapiComponentSchemas = {\n ...strapiComponentSchemas,\n [schemaName]: schema,\n };\n\n return true;\n };\n\n // Get all the route methods\n const routeMethods = routeInfo.routes.map((route: Core.Route) => route.method);\n\n const attributesToOmit = [\n 'createdAt',\n 'updatedAt',\n 'publishedAt',\n 'publishedBy',\n 'updatedBy',\n 'createdBy',\n ];\n\n const attributesForRequest = _.omit(attributes, attributesToOmit);\n // Get a list of required attribute names\n const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);\n // Build the request schemas when the route has POST or PUT methods\n if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {\n // Build localization requests schemas\n\n // Build the request schema\n Object.assign(schemas, {\n [`${typeName}Request`]: {\n type: 'object',\n required: ['data'],\n properties: {\n data: {\n ...(requiredRequestAttributes.length && { required: requiredRequestAttributes }),\n type: 'object',\n properties: cleanSchemaAttributes(attributesForRequest, {\n isRequest: true,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n },\n });\n }\n\n // Check for routes that need to return a list\n const hasListOfEntities = routeInfo.routes.filter((route: Core.Route) =>\n hasFindMethod(route.handler)\n ).length;\n\n if (hasListOfEntities) {\n // Build the list response schema\n Object.assign(schemas, {\n [`${typeName}ListResponse`]: {\n type: 'object',\n properties: {\n data: {\n type: 'array',\n items: {\n $ref: `#/components/schemas/${typeName}`,\n },\n },\n meta: {\n type: 'object',\n properties: {\n pagination: {\n type: 'object',\n properties: {\n page: { type: 'integer' },\n pageSize: { type: 'integer', minimum: 25 },\n pageCount: { type: 'integer', maximum: 1 },\n total: { type: 'integer' },\n },\n },\n },\n },\n },\n },\n });\n }\n\n const requiredAttributes = getRequiredAttributes(attributes);\n // Build the response schema\n Object.assign(schemas, {\n [`${typeName}`]: {\n type: 'object',\n ...(requiredAttributes.length && { required: requiredAttributes }),\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, { didAddStrapiComponentsToSchemas }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst buildComponentSchema = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getAllSchemasForContentType);\n};\n\nexport default buildComponentSchema;\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","oneOf","documentId","buildComponentSchema","api","loopContentTypeNames"],"mappings":";;;;;;;;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAAA,CAAe;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAAA,CAAI,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B,QAAA;AACF,IAAA;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,8BAA8B,CAAC,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,EAAW,GAAA;;AAEjF,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAAA,CAAWJ,UAAAA,CAAAA;;IAG5B,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,CAAU,GAAG;YACfoB,IAAAA,EAAM,QAAA;YACN,GAAI9B,kBAAAA,CAAmBgC,MAAM,IAAI;gBAAE9B,QAAAA,EAAUF;aAAoB;YACjEiB,UAAAA,EAAY;gBACVgC,EAAAA,EAAI;oBAAEC,KAAAA,EAAO;AAAC,wBAAA;4BAAEpB,IAAAA,EAAM;AAAS,yBAAA;AAAG,wBAAA;4BAAEA,IAAAA,EAAM;AAAS;AAAE;AAAC,iBAAA;gBACtDqB,UAAAA,EAAY;oBAAErB,IAAAA,EAAM;AAAS,iBAAA;AAC7B,gBAAA,GAAGG,sBAAsB3B,UAAAA,EAAY;AAAEM,oBAAAA;iBAAgC;AACzE;AACF,SAAA;AAEA,QAAA,CAAC,CAAA,EAAGF,QAAAA,CAAS,QAAQ,CAAC,GAAG;YACvBoB,IAAAA,EAAM,QAAA;YACNb,UAAAA,EAAY;gBACVc,IAAAA,EAAM;oBACJS,IAAAA,EAAM,CAAC,qBAAqB,EAAE9B,QAAAA,CAAAA;AAChC,iBAAA;gBACA+B,IAAAA,EAAM;oBAAEX,IAAAA,EAAM;AAAS;AACzB;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AAAE,QAAA,GAAGrB,OAAO;AAAE,QAAA,GAAGD;AAAuB,KAAA;AACjD,CAAA;AAEA,MAAM4C,uBAAuB,CAACC,GAAAA,GAAAA;;;;AAI5B,IAAA,OAAOC,qBAAqBD,GAAAA,EAAKjD,2BAAAA,CAAAA;AACnC;;;;"}
1
+ {"version":3,"file":"build-component-schema.js","sources":["../../../../server/src/services/helpers/build-component-schema.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { Core, Struct } from '@strapi/types';\n\nimport cleanSchemaAttributes from './utils/clean-schema-attributes';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport pascalCase from './utils/pascal-case';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\nconst getRequiredAttributes = (allAttributes: Struct.SchemaAttributes) => {\n const requiredAttributes: string[] = [];\n\n for (const key in allAttributes) {\n if (allAttributes[key].required) {\n requiredAttributes.push(key);\n }\n }\n\n return requiredAttributes;\n};\n\n/**\n * @description Get all open api schema objects for a given content type\n *\n * @param {object} apiInfo\n * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name\n * @property {object} apiInfo.attributes - Attributes on content type\n * @property {object} apiInfo.routeInfo - The routes for the api\n *\n * @returns {object} Open API schemas\n */\nconst getAllSchemasForContentType = ({\n routeInfo,\n attributes,\n uniqueName,\n relationTargetSchemaNames,\n}: ApiInfo & { relationTargetSchemaNames: Map<string, string> }) => {\n // Store response and request schemas in an object\n let strapiComponentSchemas = {};\n const schemas: OpenAPIV3.ComponentsObject = {};\n const typeName = pascalCase(uniqueName);\n\n // adds a ComponentSchema to the Schemas so it can be used as Ref\n const didAddStrapiComponentsToSchemas = (schemaName: string, schema: OpenAPIV3.SchemaObject) => {\n if (!Object.keys(schema) || !Object.keys(schema.properties!)) return false;\n\n // Add the Strapi components to the schema\n strapiComponentSchemas = {\n ...strapiComponentSchemas,\n [schemaName]: schema,\n };\n\n return true;\n };\n\n // Get all the route methods\n const routeMethods = routeInfo.routes.map((route: Core.Route) => route.method);\n\n const attributesToOmit = [\n 'createdAt',\n 'updatedAt',\n 'publishedAt',\n 'publishedBy',\n 'updatedBy',\n 'createdBy',\n ];\n\n const attributesForRequest = _.omit(attributes, attributesToOmit);\n // Get a list of required attribute names\n const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);\n // Build the request schemas when the route has POST or PUT methods\n if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {\n // Build localization requests schemas\n\n // Build the request schema\n Object.assign(schemas, {\n [`${typeName}Request`]: {\n type: 'object',\n required: ['data'],\n properties: {\n data: {\n ...(requiredRequestAttributes.length && { required: requiredRequestAttributes }),\n type: 'object',\n properties: cleanSchemaAttributes(attributesForRequest, {\n isRequest: true,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n },\n });\n }\n\n // Check for routes that need to return a list\n const hasListOfEntities = routeInfo.routes.filter((route: Core.Route) =>\n hasFindMethod(route.handler)\n ).length;\n\n if (hasListOfEntities) {\n // Build the list response schema\n Object.assign(schemas, {\n [`${typeName}ListResponse`]: {\n type: 'object',\n properties: {\n data: {\n type: 'array',\n items: {\n $ref: `#/components/schemas/${typeName}`,\n },\n },\n meta: {\n type: 'object',\n properties: {\n pagination: {\n type: 'object',\n properties: {\n page: { type: 'integer' },\n pageSize: { type: 'integer', minimum: 25 },\n pageCount: { type: 'integer', maximum: 1 },\n total: { type: 'integer' },\n },\n },\n },\n },\n },\n },\n });\n }\n\n const requiredAttributes = getRequiredAttributes(attributes);\n // Build the response schema\n Object.assign(schemas, {\n [`${typeName}`]: {\n type: 'object',\n ...(requiredAttributes.length && { required: requiredAttributes }),\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, {\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst getRelationTargetSchemaNames = (api: Api) => {\n const relationTargetSchemaNames = new Map<string, string>();\n\n loopContentTypeNames(api, ({ uid, uniqueName }) => {\n relationTargetSchemaNames.set(uid, pascalCase(uniqueName));\n return {};\n });\n\n return relationTargetSchemaNames;\n};\n\nconst buildComponentSchema = (\n api: Api,\n relationTargetSchemaNames = getRelationTargetSchemaNames(api)\n) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, (apiInfo) =>\n getAllSchemasForContentType({ ...apiInfo, relationTargetSchemaNames })\n );\n};\n\nexport default buildComponentSchema;\nexport { getRelationTargetSchemaNames };\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","relationTargetSchemaNames","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","oneOf","documentId","getRelationTargetSchemaNames","api","Map","loopContentTypeNames","uid","set","buildComponentSchema","apiInfo"],"mappings":";;;;;;;;;;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAAA,CAAe;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAAA,CAAI,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B,QAAA;AACF,IAAA;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,2BAAAA,GAA8B,CAAC,EACnCC,SAAS,EACTC,UAAU,EACVC,UAAU,EACVC,yBAAyB,EACoC,GAAA;;AAE7D,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAAA,CAAWL,UAAAA,CAAAA;;IAG5B,MAAMM,+BAAAA,GAAkC,CAACC,UAAAA,EAAoBC,MAAAA,GAAAA;AAC3D,QAAA,IAAI,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAAA,CAAAA,IAAW,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAAA,CAAOG,UAAU,CAAA,EAAI,OAAO,KAAA;;QAGrET,sBAAAA,GAAyB;AACvB,YAAA,GAAGA,sBAAsB;AACzB,YAAA,C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routes for the api
23
23
  *
24
24
  * @returns {object} Open API schemas
25
- */ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName })=>{
25
+ */ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName, relationTargetSchemaNames })=>{
26
26
  // Store response and request schemas in an object
27
27
  let strapiComponentSchemas = {};
28
28
  const schemas = {};
@@ -140,6 +140,7 @@ const getRequiredAttributes = (allAttributes)=>{
140
140
  type: 'string'
141
141
  },
142
142
  ...cleanSchemaAttributes(attributes, {
143
+ relationTargetSchemaNames,
143
144
  didAddStrapiComponentsToSchemas
144
145
  })
145
146
  }
@@ -161,12 +162,23 @@ const getRequiredAttributes = (allAttributes)=>{
161
162
  ...strapiComponentSchemas
162
163
  };
163
164
  };
164
- const buildComponentSchema = (api)=>{
165
+ const getRelationTargetSchemaNames = (api)=>{
166
+ const relationTargetSchemaNames = new Map();
167
+ loopContentTypeNames(api, ({ uid, uniqueName })=>{
168
+ relationTargetSchemaNames.set(uid, pascalCase(uniqueName));
169
+ return {};
170
+ });
171
+ return relationTargetSchemaNames;
172
+ };
173
+ const buildComponentSchema = (api, relationTargetSchemaNames = getRelationTargetSchemaNames(api))=>{
165
174
  // A reusable loop for building paths and component schemas
166
175
  // Uses the api param to build a new set of params for each content type
167
176
  // Passes these new params to the function provided
168
- return loopContentTypeNames(api, getAllSchemasForContentType);
177
+ return loopContentTypeNames(api, (apiInfo)=>getAllSchemasForContentType({
178
+ ...apiInfo,
179
+ relationTargetSchemaNames
180
+ }));
169
181
  };
170
182
 
171
- export { buildComponentSchema as default };
183
+ export { buildComponentSchema as default, getRelationTargetSchemaNames };
172
184
  //# sourceMappingURL=build-component-schema.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-component-schema.mjs","sources":["../../../../server/src/services/helpers/build-component-schema.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { Core, Struct } from '@strapi/types';\n\nimport cleanSchemaAttributes from './utils/clean-schema-attributes';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport pascalCase from './utils/pascal-case';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\nconst getRequiredAttributes = (allAttributes: Struct.SchemaAttributes) => {\n const requiredAttributes: string[] = [];\n\n for (const key in allAttributes) {\n if (allAttributes[key].required) {\n requiredAttributes.push(key);\n }\n }\n\n return requiredAttributes;\n};\n\n/**\n * @description Get all open api schema objects for a given content type\n *\n * @param {object} apiInfo\n * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name\n * @property {object} apiInfo.attributes - Attributes on content type\n * @property {object} apiInfo.routeInfo - The routes for the api\n *\n * @returns {object} Open API schemas\n */\nconst getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }: ApiInfo) => {\n // Store response and request schemas in an object\n let strapiComponentSchemas = {};\n const schemas: OpenAPIV3.ComponentsObject = {};\n const typeName = pascalCase(uniqueName);\n\n // adds a ComponentSchema to the Schemas so it can be used as Ref\n const didAddStrapiComponentsToSchemas = (schemaName: string, schema: OpenAPIV3.SchemaObject) => {\n if (!Object.keys(schema) || !Object.keys(schema.properties!)) return false;\n\n // Add the Strapi components to the schema\n strapiComponentSchemas = {\n ...strapiComponentSchemas,\n [schemaName]: schema,\n };\n\n return true;\n };\n\n // Get all the route methods\n const routeMethods = routeInfo.routes.map((route: Core.Route) => route.method);\n\n const attributesToOmit = [\n 'createdAt',\n 'updatedAt',\n 'publishedAt',\n 'publishedBy',\n 'updatedBy',\n 'createdBy',\n ];\n\n const attributesForRequest = _.omit(attributes, attributesToOmit);\n // Get a list of required attribute names\n const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);\n // Build the request schemas when the route has POST or PUT methods\n if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {\n // Build localization requests schemas\n\n // Build the request schema\n Object.assign(schemas, {\n [`${typeName}Request`]: {\n type: 'object',\n required: ['data'],\n properties: {\n data: {\n ...(requiredRequestAttributes.length && { required: requiredRequestAttributes }),\n type: 'object',\n properties: cleanSchemaAttributes(attributesForRequest, {\n isRequest: true,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n },\n });\n }\n\n // Check for routes that need to return a list\n const hasListOfEntities = routeInfo.routes.filter((route: Core.Route) =>\n hasFindMethod(route.handler)\n ).length;\n\n if (hasListOfEntities) {\n // Build the list response schema\n Object.assign(schemas, {\n [`${typeName}ListResponse`]: {\n type: 'object',\n properties: {\n data: {\n type: 'array',\n items: {\n $ref: `#/components/schemas/${typeName}`,\n },\n },\n meta: {\n type: 'object',\n properties: {\n pagination: {\n type: 'object',\n properties: {\n page: { type: 'integer' },\n pageSize: { type: 'integer', minimum: 25 },\n pageCount: { type: 'integer', maximum: 1 },\n total: { type: 'integer' },\n },\n },\n },\n },\n },\n },\n });\n }\n\n const requiredAttributes = getRequiredAttributes(attributes);\n // Build the response schema\n Object.assign(schemas, {\n [`${typeName}`]: {\n type: 'object',\n ...(requiredAttributes.length && { required: requiredAttributes }),\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, { didAddStrapiComponentsToSchemas }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst buildComponentSchema = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getAllSchemasForContentType);\n};\n\nexport default buildComponentSchema;\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","oneOf","documentId","buildComponentSchema","api","loopContentTypeNames"],"mappings":";;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAAA,CAAe;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAAA,CAAI,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B,QAAA;AACF,IAAA;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,8BAA8B,CAAC,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,EAAW,GAAA;;AAEjF,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAAA,CAAWJ,UAAAA,CAAAA;;IAG5B,MAAMK,+BAAAA,GAAkC,CAACC,UAAAA,EAAoBC,MAAAA,GAAAA;AAC3D,QAAA,IAAI,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAAA,CAAAA,IAAW,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAAA,CAAOG,UAAU,CAAA,EAAI,OAAO,KAAA;;QAGrET,sBAAAA,GAAyB;AACvB,YAAA,GAAGA,sBAAsB;AACzB,YAAA,CAACK,aAAaC;AAChB,SAAA;QAEA,OAAO,IAAA;AACT,IAAA,CAAA;;IAGA,MAAMI,YAAAA,GAAeb,UAAUc,MAAM,CAACC,GAAG,CAAC,CAACC,KAAAA,GAAsBA,KAAAA,CAAMC,MAAM,CAAA;AAE7E,IAAA,MAAMC,gBAAAA,GAAmB;AACvB,QAAA,WAAA;AACA,QAAA,WAAA;AACA,QAAA,aAAA;AACA,QAAA,aAAA;AACA,QAAA,WAAA;AACA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JS,IAAAA,EAAM,CAAC,qBAAqB,EAAE9B,QAAAA,CAAAA;AAChC,iBAAA;gBACA+B,IAAAA,EAAM;oBAAEX,IAAAA,EAAM;AAAS;AACzB;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AAAE,QAAA,GAAGrB,OAAO;AAAE,QAAA,GAAGD;AAAuB,KAAA;AACjD,CAAA;AAEA,MAAM4C,uBAAuB,CAACC,GAAAA,GAAAA;;;;AAI5B,IAAA,OAAOC,qBAAqBD,GAAAA,EAAKjD,2BAAAA,CAAAA;AACnC;;;;"}
1
+ {"version":3,"file":"build-component-schema.mjs","sources":["../../../../server/src/services/helpers/build-component-schema.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { Core, Struct } from '@strapi/types';\n\nimport cleanSchemaAttributes from './utils/clean-schema-attributes';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport pascalCase from './utils/pascal-case';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\nconst getRequiredAttributes = (allAttributes: Struct.SchemaAttributes) => {\n const requiredAttributes: string[] = [];\n\n for (const key in allAttributes) {\n if (allAttributes[key].required) {\n requiredAttributes.push(key);\n }\n }\n\n return requiredAttributes;\n};\n\n/**\n * @description Get all open api schema objects for a given content type\n *\n * @param {object} apiInfo\n * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name\n * @property {object} apiInfo.attributes - Attributes on content type\n * @property {object} apiInfo.routeInfo - The routes for the api\n *\n * @returns {object} Open API schemas\n */\nconst getAllSchemasForContentType = ({\n routeInfo,\n attributes,\n uniqueName,\n relationTargetSchemaNames,\n}: ApiInfo & { relationTargetSchemaNames: Map<string, string> }) => {\n // Store response and request schemas in an object\n let strapiComponentSchemas = {};\n const schemas: OpenAPIV3.ComponentsObject = {};\n const typeName = pascalCase(uniqueName);\n\n // adds a ComponentSchema to the Schemas so it can be used as Ref\n const didAddStrapiComponentsToSchemas = (schemaName: string, schema: OpenAPIV3.SchemaObject) => {\n if (!Object.keys(schema) || !Object.keys(schema.properties!)) return false;\n\n // Add the Strapi components to the schema\n strapiComponentSchemas = {\n ...strapiComponentSchemas,\n [schemaName]: schema,\n };\n\n return true;\n };\n\n // Get all the route methods\n const routeMethods = routeInfo.routes.map((route: Core.Route) => route.method);\n\n const attributesToOmit = [\n 'createdAt',\n 'updatedAt',\n 'publishedAt',\n 'publishedBy',\n 'updatedBy',\n 'createdBy',\n ];\n\n const attributesForRequest = _.omit(attributes, attributesToOmit);\n // Get a list of required attribute names\n const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);\n // Build the request schemas when the route has POST or PUT methods\n if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {\n // Build localization requests schemas\n\n // Build the request schema\n Object.assign(schemas, {\n [`${typeName}Request`]: {\n type: 'object',\n required: ['data'],\n properties: {\n data: {\n ...(requiredRequestAttributes.length && { required: requiredRequestAttributes }),\n type: 'object',\n properties: cleanSchemaAttributes(attributesForRequest, {\n isRequest: true,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n },\n });\n }\n\n // Check for routes that need to return a list\n const hasListOfEntities = routeInfo.routes.filter((route: Core.Route) =>\n hasFindMethod(route.handler)\n ).length;\n\n if (hasListOfEntities) {\n // Build the list response schema\n Object.assign(schemas, {\n [`${typeName}ListResponse`]: {\n type: 'object',\n properties: {\n data: {\n type: 'array',\n items: {\n $ref: `#/components/schemas/${typeName}`,\n },\n },\n meta: {\n type: 'object',\n properties: {\n pagination: {\n type: 'object',\n properties: {\n page: { type: 'integer' },\n pageSize: { type: 'integer', minimum: 25 },\n pageCount: { type: 'integer', maximum: 1 },\n total: { type: 'integer' },\n },\n },\n },\n },\n },\n },\n });\n }\n\n const requiredAttributes = getRequiredAttributes(attributes);\n // Build the response schema\n Object.assign(schemas, {\n [`${typeName}`]: {\n type: 'object',\n ...(requiredAttributes.length && { required: requiredAttributes }),\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, {\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst getRelationTargetSchemaNames = (api: Api) => {\n const relationTargetSchemaNames = new Map<string, string>();\n\n loopContentTypeNames(api, ({ uid, uniqueName }) => {\n relationTargetSchemaNames.set(uid, pascalCase(uniqueName));\n return {};\n });\n\n return relationTargetSchemaNames;\n};\n\nconst buildComponentSchema = (\n api: Api,\n relationTargetSchemaNames = getRelationTargetSchemaNames(api)\n) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, (apiInfo) =>\n getAllSchemasForContentType({ ...apiInfo, relationTargetSchemaNames })\n );\n};\n\nexport default buildComponentSchema;\nexport { getRelationTargetSchemaNames };\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","relationTargetSchemaNames","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","oneOf","documentId","getRelationTargetSchemaNames","api","Map","loopContentTypeNames","uid","set","buildComponentSchema","apiInfo"],"mappings":";;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAAA,CAAe;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAAA,CAAI,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GAAAA;AACpC,IAAA,MAAM9C,4BAA4B,IAAI+C,GAAAA,EAAAA;AAEtCC,IAAAA,oBAAAA,CAAqBF,KAAK,CAAC,EAAEG,GAAG,EAAElD,UAAU,EAAE,GAAA;QAC5CC,yBAAAA,CAA0BkD,GAAG,CAACD,GAAAA,EAAK7C,UAAAA,CAAWL,UAAAA,CAAAA,CAAAA;AAC9C,QAAA,OAAO,EAAC;AACV,IAAA,CAAA,CAAA;IAEA,OAAOC,yBAAAA;AACT;AAEA,MAAMmD,oBAAAA,GAAuB,CAC3BL,GAAAA,EACA9C,yBAAAA,GAA4B6C,6BAA6BC,GAAAA,CAAI,GAAA;;;;AAK7D,IAAA,OAAOE,oBAAAA,CAAqBF,GAAAA,EAAK,CAACM,OAAAA,GAChCxD,2BAAAA,CAA4B;AAAE,YAAA,GAAGwD,OAAO;AAAEpD,YAAAA;AAA0B,SAAA,CAAA,CAAA;AAExE;;;;"}
@@ -18,7 +18,7 @@ var pascalCase = require('./pascal-case.js');
18
18
  * @description - Converts types found on attributes to OpenAPI acceptable data types
19
19
  *
20
20
  * @returns Attributes using OpenAPI acceptable data types
21
- */ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = false, didAddStrapiComponentsToSchemas })=>{
21
+ */ const cleanSchemaAttributes = (attributes, { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas })=>{
22
22
  const schemaAttributes = {};
23
23
  for (const prop of Object.keys(attributes)){
24
24
  const attribute = attributes[prop];
@@ -160,8 +160,8 @@ var pascalCase = require('./pascal-case.js');
160
160
  }
161
161
  },
162
162
  ...cleanSchemaAttributes(componentAttributes, {
163
- typeMap,
164
163
  isRequest,
164
+ relationTargetSchemaNames,
165
165
  didAddStrapiComponentsToSchemas
166
166
  })
167
167
  }
@@ -207,8 +207,8 @@ var pascalCase = require('./pascal-case.js');
207
207
  ]
208
208
  },
209
209
  ...cleanSchemaAttributes(componentAttributes, {
210
- typeMap,
211
210
  isRequest,
211
+ relationTargetSchemaNames,
212
212
  didAddStrapiComponentsToSchemas
213
213
  })
214
214
  }
@@ -262,7 +262,7 @@ var pascalCase = require('./pascal-case.js');
262
262
  break;
263
263
  }
264
264
  schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(imageAttributes, {
265
- typeMap,
265
+ relationTargetSchemaNames,
266
266
  didAddStrapiComponentsToSchemas
267
267
  }));
268
268
  break;
@@ -288,17 +288,18 @@ var pascalCase = require('./pascal-case.js');
288
288
  } : oneOfType;
289
289
  break;
290
290
  }
291
- if (!('target' in attribute) || !attribute.target || typeMap.has(attribute.target)) {
292
- schemaAttributes[prop] = getSchemaData(isListOfEntities, {});
291
+ const targetSchemaName = 'target' in attribute && attribute.target ? relationTargetSchemaNames?.get(attribute.target) : undefined;
292
+ if (targetSchemaName) {
293
+ const targetSchema = {
294
+ $ref: `#/components/schemas/${targetSchemaName}`
295
+ };
296
+ schemaAttributes[prop] = isListOfEntities ? {
297
+ type: 'array',
298
+ items: targetSchema
299
+ } : targetSchema;
293
300
  break;
294
301
  }
295
- typeMap.set(attribute.target, true);
296
- const targetAttributes = strapi.contentType(attribute.target).attributes;
297
- schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(targetAttributes, {
298
- typeMap,
299
- isRequest,
300
- didAddStrapiComponentsToSchemas
301
- }));
302
+ schemaAttributes[prop] = getSchemaData(isListOfEntities, {});
302
303
  break;
303
304
  }
304
305
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"clean-schema-attributes.js","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n typeMap?: Map<string, boolean>;\n isRequest?: boolean;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { typeMap = new Map(), isRequest = false, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, { typeMap, didAddStrapiComponentsToSchemas })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n if (!('target' in attribute) || !attribute.target || typeMap.has(attribute.target)) {\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n\n typeMap.set(attribute.target, true);\n const targetAttributes = strapi.contentType(attribute.target).attributes;\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(targetAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n })\n );\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","typeMap","Map","isRequest","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","target","has","set","targetAttributes","Error"],"mappings":";;;;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAAA,GAAqB,CAAA,EAAGC,UAAAA,CAAWH,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAAA,EAAO;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAAA,CAAAA,CAAoB;AACrD,IAAA;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;AAIC,IACD,MAAME,qBAAAA,GAAwB,CAC5BC,UAAAA,EACA,EAAEC,OAAAA,GAAU,IAAIC,GAAAA,EAAK,EAAEC,SAAAA,GAAY,KAAK,EAAEC,+BAA+B,EAAW,GAAA;AAEpF,IAAA,MAAMC,mBAAuF,EAAC;AAE9F,IAAA,KAAK,MAAMC,IAAAA,IAAQC,MAAAA,CAAOC,IAAI,CAACR,UAAAA,CAAAA,CAAa;QAC1C,MAAMS,SAAAA,GAAYT,UAAU,CAACM,IAAAA,CAAK;AAElC,QAAA,OAAQG,UAAUC,IAAI;YACpB,KAAK,UAAA;AAAY,gBAAA;AACf,oBAAA,IAAI,CAACP,SAAAA,EAAW;AACd,wBAAA;AACF,oBAAA;oBAEAE,gBAAgB,CAACC,KAAK,GAAG;wBAAEI,IAAAA,EAAM,QAAA;wBAAUC,MAAAA,EAAQ,UAAA;wBAAYC,OAAAA,EAAS;AAAU,qBAAA;AAClF,oBAAA;AACF,gBAAA;YACA,KAAK,OAAA;AAAS,gBAAA;oBACZP,gBAAgB,CAACC,KAAK,GAAG;wBAAEI,IAAAA,EAAM,QAAA;wBAAUC,MAAAA,EAAQ;AAAQ,qBAAA;AAC3D,oBAAA;AACF,gBAAA;YACA,KAA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AAA;AAE1D,wBAAA;AACF,oBAAA;AAEAzC,oBAAAA,OAAAA,CAAQiD,GAAG,CAACzC,SAAAA,CAAUuC,MAAM,EAAE,IAAA,CAAA;AAC9B,oBAAA,MAAMG,mBAAmBjC,MAAAA,CAAOuB,WAAW,CAAChC,SAAAA,CAAUuC,MAAM,EAAEhD,UAAU;AAExEK,oBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CACvBH,gBAAAA,EACA3C,sBAAsBoD,gBAAAA,EAAkB;AACtClD,wBAAAA,OAAAA;AACAE,wBAAAA,SAAAA;AACAC,wBAAAA;AACF,qBAAA,CAAA,CAAA;AAGF,oBAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIgD,MAAM,CAAC,aAAa,EAAE3C,SAAAA,CAAUC,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF,gBAAA;AACF;AACF,IAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
1
+ {"version":3,"file":"clean-schema-attributes.js","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n isRequest?: boolean;\n relationTargetSchemaNames?: Map<string, string>;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, {\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n const targetSchemaName =\n 'target' in attribute && attribute.target\n ? relationTargetSchemaNames?.get(attribute.target)\n : undefined;\n\n if (targetSchemaName) {\n const targetSchema: OpenAPIV3.ReferenceObject = {\n $ref: `#/components/schemas/${targetSchemaName}`,\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: targetSchema }\n : targetSchema;\n\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","isRequest","relationTargetSchemaNames","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","targetSchemaName","target","get","undefined","targetSchema","Error"],"mappings":";;;;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;A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AgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CAAcH,kBAAkB,EAAC,CAAA;AAE1D,oBAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIW,MAAM,CAAC,aAAa,EAAE5C,SAAAA,CAAUC,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF,gBAAA;AACF;AACF,IAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
@@ -16,7 +16,7 @@ import pascalCase from './pascal-case.mjs';
16
16
  * @description - Converts types found on attributes to OpenAPI acceptable data types
17
17
  *
18
18
  * @returns Attributes using OpenAPI acceptable data types
19
- */ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = false, didAddStrapiComponentsToSchemas })=>{
19
+ */ const cleanSchemaAttributes = (attributes, { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas })=>{
20
20
  const schemaAttributes = {};
21
21
  for (const prop of Object.keys(attributes)){
22
22
  const attribute = attributes[prop];
@@ -158,8 +158,8 @@ import pascalCase from './pascal-case.mjs';
158
158
  }
159
159
  },
160
160
  ...cleanSchemaAttributes(componentAttributes, {
161
- typeMap,
162
161
  isRequest,
162
+ relationTargetSchemaNames,
163
163
  didAddStrapiComponentsToSchemas
164
164
  })
165
165
  }
@@ -205,8 +205,8 @@ import pascalCase from './pascal-case.mjs';
205
205
  ]
206
206
  },
207
207
  ...cleanSchemaAttributes(componentAttributes, {
208
- typeMap,
209
208
  isRequest,
209
+ relationTargetSchemaNames,
210
210
  didAddStrapiComponentsToSchemas
211
211
  })
212
212
  }
@@ -260,7 +260,7 @@ import pascalCase from './pascal-case.mjs';
260
260
  break;
261
261
  }
262
262
  schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(imageAttributes, {
263
- typeMap,
263
+ relationTargetSchemaNames,
264
264
  didAddStrapiComponentsToSchemas
265
265
  }));
266
266
  break;
@@ -286,17 +286,18 @@ import pascalCase from './pascal-case.mjs';
286
286
  } : oneOfType;
287
287
  break;
288
288
  }
289
- if (!('target' in attribute) || !attribute.target || typeMap.has(attribute.target)) {
290
- schemaAttributes[prop] = getSchemaData(isListOfEntities, {});
289
+ const targetSchemaName = 'target' in attribute && attribute.target ? relationTargetSchemaNames?.get(attribute.target) : undefined;
290
+ if (targetSchemaName) {
291
+ const targetSchema = {
292
+ $ref: `#/components/schemas/${targetSchemaName}`
293
+ };
294
+ schemaAttributes[prop] = isListOfEntities ? {
295
+ type: 'array',
296
+ items: targetSchema
297
+ } : targetSchema;
291
298
  break;
292
299
  }
293
- typeMap.set(attribute.target, true);
294
- const targetAttributes = strapi.contentType(attribute.target).attributes;
295
- schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(targetAttributes, {
296
- typeMap,
297
- isRequest,
298
- didAddStrapiComponentsToSchemas
299
- }));
300
+ schemaAttributes[prop] = getSchemaData(isListOfEntities, {});
300
301
  break;
301
302
  }
302
303
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"clean-schema-attributes.mjs","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n typeMap?: Map<string, boolean>;\n isRequest?: boolean;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { typeMap = new Map(), isRequest = false, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, { typeMap, didAddStrapiComponentsToSchemas })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n if (!('target' in attribute) || !attribute.target || typeMap.has(attribute.target)) {\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n\n typeMap.set(attribute.target, true);\n const targetAttributes = strapi.contentType(attribute.target).attributes;\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(targetAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n })\n );\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","typeMap","Map","isRequest","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","target","has","set","targetAttributes","Error"],"mappings":";;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAAA,GAAqB,CAAA,EAAGC,UAAAA,CAAWH,SAAAA,CAA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oD,gBAAAA,EAAkB;AACtClD,wBAAAA,OAAAA;AACAE,wBAAAA,SAAAA;AACAC,wBAAAA;AACF,qBAAA,CAAA,CAAA;AAGF,oBAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIgD,MAAM,CAAC,aAAa,EAAE3C,SAAAA,CAAUC,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF,gBAAA;AACF;AACF,IAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
1
+ {"version":3,"file":"clean-schema-attributes.mjs","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n isRequest?: boolean;\n relationTargetSchemaNames?: Map<string, string>;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, {\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n const targetSchemaName =\n 'target' in attribute && attribute.target\n ? relationTargetSchemaNames?.get(attribute.target)\n : undefined;\n\n if (targetSchemaName) {\n const targetSchema: OpenAPIV3.ReferenceObject = {\n $ref: `#/components/schemas/${targetSchemaName}`,\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: targetSchema }\n : targetSchema;\n\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","isRequest","relationTargetSchemaNames","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","targetSchemaName","target","get","undefined","targetSchema","Error"],"mappings":";;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAAA,GAAqB,CAAA,EAAGC,UAAAA,CAAWH,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAAA,EAAO;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAAA,CAAAA,CAAoB;AACrD,IAAA;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;IAKA,MAAME,qBAAAA,GAAwB,CAC5BC,UAAAA,EACA,EAAEC,SAAAA,GAA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#__PURE__*/_interopDefault(_);
26
26
  const uniqueName = api.name === contentTypeName ? apiName : `${apiName} - ${___default.default.upperFirst(contentTypeName)}`;
27
27
  const apiInfo = {
28
28
  ...api,
29
+ uid,
29
30
  routeInfo,
30
31
  attributes,
31
32
  uniqueName,
@@ -1 +1 @@
1
- {"version":3,"file":"loop-content-type-names.js","sources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;;;;;;;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC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ources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n uid,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;;;;;;;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC;AACd,IAAA,KAAK,MAAMC,eAAAA,IAAmBH,GAAAA,CAAII,OAAO,CAAE;;AAEzC,QAAA,MAAMC,GAAAA,GAAM,CAAA,EAAGL,GAAAA,CAAIM,MAAM,CAAC,EAAE,EAAEN,GAAAA,CAAIO,IAAI,CAAC,CAAC,EAAEJ,eAAAA,CAAAA,CAAiB;QAE3D,MAAM,EAAEK,UAAU,EAAEC,IAAAA,EAAMC,eAAe,EAAEC,IAAI,EAAE,GAAGC,MAAAA,CAAOC,WAAW,CAACR,GAAAA,CAAAA;;QAGvE,MAAMS,SAAAA,GACJd,IAAIM,MAAM,KAAK,WAEXM,MAAAA,CAAOG,MAAM,CAACf,GAAAA,CAAIO,IAAI,CAAA,CAAES,MAAM,CAAC,aAAA,CAAc,GAC7CJ,MAAAA,CAAOZ,GAAG,CAACA,IAAIO,IAAI,CAAA,CAAES,MAAM,CAACb,eAAAA,CAAgB;;AAGlD,QAAA,IAAI,CAACW,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;;AAGA,QAAA,MAAMG,OAAAA,GAAUC,kBAAAA,CAAEC,UAAU,CAACnB,IAAIO,IAAI,CAAA;;AAGrC,QAAA,MAAMa,UAAAA,GACJpB,GAAAA,CAAIO,IAAI,KAAKJ,eAAAA,GAAkBc,OAAAA,GAAU,CAAA,EAAGA,OAAAA,CAAQ,GAAG,EAAEC,kBAAAA,CAAEC,UAAU,CAAChB,eAAAA,CAAAA,CAAAA,CAAkB;AAE1F,QAAA,MAAMkB,OAAAA,GAAU;AACd,YAAA,GAAGrB,GAAG;AACNK,YAAAA,GAAAA;AACAS,YAAAA,SAAAA;AACAN,YAAAA,UAAAA;AACAY,YAAAA,UAAAA;AACAV,YAAAA,eAAAA;AACAC,YAAAA;AACF,SAAA;QAEAT,MAAAA,GAAS;AACP,YAAA,GAAGA,MAAM;AACT,YAAA,GAAGD,SAASoB,OAAAA;AACd,SAAA;AACF,IAAA;IAEA,OAAOnB,MAAAA;AACT;;;;"}
@@ -20,6 +20,7 @@ import _ from 'lodash';
20
20
  const uniqueName = api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;
21
21
  const apiInfo = {
22
22
  ...api,
23
+ uid,
23
24
  routeInfo,
24
25
  attributes,
25
26
  uniqueName,
@@ -1 +1 @@
1
- {"version":3,"file":"loop-content-type-names.mjs","sources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC;AACd,IAAA,KAAK,MAAMC,eAAAA,IAAmBH,GAAAA,CAAII,OAAO,CAAE;;AAEzC,QAAA,MAAMC,GAAAA,GAAM,CAAA,EAAGL,GAAAA,CAAIM,MAAM,CAAC,EAAE,EAAEN,GAAAA,CAAIO,IAAI,CAAC,CAAC,EAAEJ,eAAAA,CAAAA,CAAiB;QAE3D,MAAM,EAAEK,UAAU,EAAEC,IAAAA,EAAMC,eAAe,EAAEC,IAAI,EAAE,GAAGC,MAAAA,CAAOC,WAAW,CAACR,GAAAA,CAAAA;;QAGvE,MAAMS,SAAAA,GACJd,IAAIM,MAAM,KAAK,WAEXM,MAAAA,CAAOG,MAAM,CAACf,GAAAA,CAAIO,IAAI,CAAA,CAAES,MAAM,CAAC,aAAA,CAAc,GAC7CJ,MAAAA,CAAOZ,GAAG,CAACA,IAAIO,IAAI,CAAA,CAAES,MAAM,CAACb,eAAAA,CAAgB;;AAGlD,QAAA,IAAI,CAACW,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;;AAGA,QAAA,MAAMG,OAAAA,GAAUC,CAAAA,CAAEC,UAAU,CAACnB,IAAIO,IAAI,CAAA;;AAGrC,QAAA,MAAMa,UAAAA,GACJpB,GAAAA,CAAIO,IAAI,KAAKJ,eAAAA,GAAkBc,OAAAA,GAAU,CAAA,EAAGA,OAAAA,CAAQ,GAAG,EAAEC,CAAAA,CAAEC,UAAU,CAAChB,eAAAA,CAAAA,CAAAA,CAAkB;AAE1F,QAAA,MAAMkB,OAAAA,GAAU;AACd,YAAA,GAAGrB,GAAG;AACNc,YAAAA,SAAAA;AACAN,YAAAA,UAAAA;AACAY,YAAAA,UAAAA;AACAV,YAAAA,eAAAA;AACAC,YAAAA;AACF,SAAA;QAEAT,MAAAA,GAAS;AACP,YAAA,GAAGA,MAAM;AACT,YAAA,GAAGD,SAASoB,OAAAA;AACd,SAAA;AACF,IAAA;IAEA,OAAOnB,MAAAA;AACT;;;;"}
1
+ {"version":3,"file":"loop-content-type-names.mjs","sources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n uid,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC;AACd,IAAA,KAAK,MAAMC,eAAAA,IAAmBH,GAAAA,CAAII,OAAO,CAAE;;AAEzC,QAAA,MAAMC,GAAAA,GAAM,CAAA,EAAGL,GAAAA,CAAIM,MAAM,CAAC,EAAE,EAAEN,GAAAA,CAAIO,IAAI,CAAC,CAAC,EAAEJ,eAAAA,CAAAA,CAAiB;QAE3D,MAAM,EAAEK,UAAU,EAAEC,IAAAA,EAAMC,eAAe,EAAEC,IAAI,EAAE,GAAGC,MAAAA,CAAOC,WAAW,CAACR,GAAAA,CAAAA;;QAGvE,MAAMS,SAAAA,GACJd,IAAIM,MAAM,KAAK,WAEXM,MAAAA,CAAOG,MAAM,CAACf,GAAAA,CAAIO,IAAI,CAAA,CAAES,MAAM,CAAC,aAAA,CAAc,GAC7CJ,MAAAA,CAAOZ,GAAG,CAACA,IAAIO,IAAI,CAAA,CAAES,MAAM,CAACb,eAAAA,CAAgB;;AAGlD,QAAA,IAAI,CAACW,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;;AAGA,QAAA,MAAMG,OAAAA,GAAUC,CAAAA,CAAEC,UAAU,CAACnB,IAAIO,IAAI,CAAA;;AAGrC,QAAA,MAAMa,UAAAA,GACJpB,GAAAA,CAAIO,IAAI,KAAKJ,eAAAA,GAAkBc,OAAAA,GAAU,CAAA,EAAGA,OAAAA,CAAQ,GAAG,EAAEC,CAAAA,CAAEC,UAAU,CAAChB,eAAAA,CAAAA,CAAAA,CAAkB;AAE1F,QAAA,MAAMkB,OAAAA,GAAU;AACd,YAAA,GAAGrB,GAAG;AACNK,YAAAA,GAAAA;AACAS,YAAAA,SAAAA;AACAN,YAAAA,UAAAA;AACAY,YAAAA,UAAAA;AACAV,YAAAA,eAAAA;AACAC,YAAAA;AACF,SAAA;QAEAT,MAAAA,GAAS;AACP,YAAA,GAAGA,MAAM;AACT,YAAA,GAAGD,SAASoB,OAAAA;AACd,SAAA;AACF,IAAA;IAEA,OAAOnB,MAAAA;AACT;;;;"}
@@ -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,GAAI,YAAY;IAAE,MAAM,EAAE,IAAI,CAAC,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"}
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,GAAI,YAAY;IAAE,MAAM,EAAE,IAAI,CAAC,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;CAmH5C,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import type { Api } from '../../types';
2
- declare const buildComponentSchema: (api: Api) => {};
2
+ declare const getRelationTargetSchemaNames: (api: Api) => Map<string, string>;
3
+ declare const buildComponentSchema: (api: Api, relationTargetSchemaNames?: Map<string, string>) => {};
3
4
  export default buildComponentSchema;
5
+ export { getRelationTargetSchemaNames };
4
6
  //# sourceMappingURL=build-component-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-component-schema.d.ts","sourceRoot":"","sources":["../../../../../server/src/services/helpers/build-component-schema.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,GAAG,EAAW,MAAM,aAAa,CAAC;AAgJhD,QAAA,MAAM,oBAAoB,GAAI,KAAK,GAAG,OAKrC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"build-component-schema.d.ts","sourceRoot":"","sources":["../../../../../server/src/services/helpers/build-component-schema.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,GAAG,EAAW,MAAM,aAAa,CAAC;AAwJhD,QAAA,MAAM,4BAA4B,GAAI,KAAK,GAAG,wBAS7C,CAAC;AAEF,QAAA,MAAM,oBAAoB,GACxB,KAAK,GAAG,EACR,+CAA6D,OAQ9D,CAAC;AAEF,eAAe,oBAAoB,CAAC;AACpC,OAAO,EAAE,4BAA4B,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import builApiEndpointPath from './build-api-endpoint-path';
2
- import buildComponentSchema from './build-component-schema';
3
- export { builApiEndpointPath, buildComponentSchema };
2
+ import buildComponentSchema, { getRelationTargetSchemaNames } from './build-component-schema';
3
+ export { builApiEndpointPath, buildComponentSchema, getRelationTargetSchemaNames };
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../server/src/services/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,2BAA2B,CAAC;AAC5D,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../server/src/services/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,2BAA2B,CAAC;AAC5D,OAAO,oBAAoB,EAAE,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AAE9F,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import type { Struct } from '@strapi/types';
2
2
  import type { OpenAPIV3 } from 'openapi-types';
3
3
  interface Options {
4
- typeMap?: Map<string, boolean>;
5
4
  isRequest?: boolean;
5
+ relationTargetSchemaNames?: Map<string, string>;
6
6
  didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;
7
7
  }
8
8
  /**
@@ -10,6 +10,6 @@ interface Options {
10
10
  *
11
11
  * @returns Attributes using OpenAPI acceptable data types
12
12
  */
13
- declare const cleanSchemaAttributes: (attributes: Struct.SchemaAttributes, { typeMap, isRequest, didAddStrapiComponentsToSchemas }: Options) => Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>;
13
+ declare const cleanSchemaAttributes: (attributes: Struct.SchemaAttributes, { isRequest, relationTargetSchemaNames, didAddStrapiComponentsToSchemas }: Options) => Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>;
14
14
  export default cleanSchemaAttributes;
15
15
  //# sourceMappingURL=clean-schema-attributes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clean-schema-attributes.d.ts","sourceRoot":"","sources":["../../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK/C,UAAU,OAAO;IACf,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+BAA+B,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5E;AAgBD;;;;GAIG;AACH,QAAA,MAAM,qBAAqB,GACzB,YAAY,MAAM,CAAC,gBAAgB,EACnC,yDAA6E,OAAO,KACnF,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,eAAe,CA+NnE,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"clean-schema-attributes.d.ts","sourceRoot":"","sources":["../../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK/C,UAAU,OAAO;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yBAAyB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,+BAA+B,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5E;AAgBD;;;;GAIG;AACH,QAAA,MAAM,qBAAqB,GACzB,YAAY,MAAM,CAAC,gBAAgB,EACnC,2EAAmF,OAAO,KACzF,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,eAAe,CAmOnE,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loop-content-type-names.d.ts","sourceRoot":"","sources":["../../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;GAEG;AACH,QAAA,MAAM,oBAAoB,GAAI,KAAK,GAAG,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,KAAK,GAAG,OA2CvE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"loop-content-type-names.d.ts","sourceRoot":"","sources":["../../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;GAEG;AACH,QAAA,MAAM,oBAAoB,GAAI,KAAK,GAAG,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,KAAK,GAAG,OA4CvE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -14,6 +14,7 @@ export type PluginConfig = OpenAPIV3.Document & {
14
14
  };
15
15
  };
16
16
  export interface ApiInfo {
17
+ uid: string;
17
18
  routeInfo: Core.Router;
18
19
  attributes: Struct.SchemaAttributes;
19
20
  uniqueName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../server/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,MAAM;IACrB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,GAAG;IAC9C,IAAI,EAAE,SAAS,CAAC,UAAU,GAAG;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,iBAAiB,EAAE;QACjB,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACzB,mBAAmB,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;KAClF,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC,gBAAgB,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,GAAG,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../server/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,MAAM;IACrB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,GAAG;IAC9C,IAAI,EAAE,SAAS,CAAC,UAAU,GAAG;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,iBAAiB,EAAE;QACjB,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACzB,mBAAmB,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;KAClF,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC,gBAAgB,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,GAAG,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-documentation",
3
- "version": "5.56.0",
3
+ "version": "5.57.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.56.0",
66
+ "@strapi/admin": "5.57.0",
67
67
  "@strapi/design-system": "2.2.4",
68
68
  "@strapi/icons": "2.2.4",
69
- "@strapi/utils": "5.56.0",
69
+ "@strapi/utils": "5.57.0",
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.56.0",
86
- "@strapi/strapi": "5.56.0",
87
- "@strapi/types": "5.56.0",
85
+ "@strapi/admin-test-utils": "5.57.0",
86
+ "@strapi/strapi": "5.57.0",
87
+ "@strapi/types": "5.57.0",
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",