@strapi/plugin-documentation 5.57.0 → 5.59.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.
@@ -46,7 +46,7 @@ const getRequiredAttributes = (allAttributes)=>{
46
46
  return true;
47
47
  };
48
48
  // Get all the route methods
49
- const routeMethods = routeInfo.routes.map((route)=>route.method);
49
+ const routeMethods = new Set(routeInfo.routes.map((route)=>route.method));
50
50
  const attributesToOmit = [
51
51
  'createdAt',
52
52
  'updatedAt',
@@ -59,7 +59,7 @@ const getRequiredAttributes = (allAttributes)=>{
59
59
  // Get a list of required attribute names
60
60
  const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);
61
61
  // Build the request schemas when the route has POST or PUT methods
62
- if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {
62
+ if (routeMethods.has('POST') || routeMethods.has('PUT')) {
63
63
  // Build localization requests schemas
64
64
  // Build the request schema
65
65
  Object.assign(schemas, {
@@ -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 = ({\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,CAACK,aAAaC;AAChB,SAAA;QAEA,OAAO,IAAA;AACT,IAAA,CAAA;;IAGA,MAAMI,YAAAA,GAAed,UAAUe,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,QAAA;AACD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A,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,+BAA+B,CAACC,GAAAA,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;;;;;"}
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 = new Set(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.has('POST') || routeMethods.has('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","Set","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","has","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,CAACK,aAAaC;AAChB,SAAA;QAEA,OAAO,IAAA;AACT,IAAA,CAA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,UAAAA,EAAY;oBAAErB,IAAAA,EAAM;AAAS,iBAAA;AAC7B,gBAAA,GAAGG,sBAAsB7B,UAAAA,EAAY;AACnCE,oBAAAA,yBAAAA;AACAK,oBAAAA;iBACF;AACF;AACF,SAAA;AAEA,QAAA,CAAC,CAAA,EAAGF,QAAAA,CAAS,QAAQ,CAAC,GAAG;YACvBqB,IAAAA,EAAM,QAAA;YACNd,UAAAA,EAAY;gBACVe,IAAAA,EAAM;oBACJS,IAAAA,EAAM,CAAC,qBAAqB,EAAE/B,QAAAA,CAAAA;AAChC,iBAAA;gBACAgC,IAAAA,EAAM;oBAAEX,IAAAA,EAAM;AAAS;AACzB;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AAAE,QAAA,GAAGtB,OAAO;AAAE,QAAA,GAAGD;AAAuB,KAAA;AACjD,CAAA;AAEA,MAAM6C,+BAA+B,CAACC,GAAAA,GAAAA;AACpC,IAAA,MAAM/C,4BAA4B,IAAIgD,GAAAA,EAAAA;AAEtCC,IAAAA,oBAAAA,CAAqBF,KAAK,CAAC,EAAEG,GAAG,EAAEnD,UAAU,EAAE,GAAA;QAC5CC,yBAAAA,CAA0BmD,GAAG,CAACD,GAAAA,EAAK9C,UAAAA,CAAWL,UAAAA,CAAAA,CAAAA;AAC9C,QAAA,OAAO,EAAC;AACV,IAAA,CAAA,CAAA;IAEA,OAAOC,yBAAAA;AACT;AAEA,MAAMoD,oBAAAA,GAAuB,CAC3BL,GAAAA,EACA/C,yBAAAA,GAA4B8C,6BAA6BC,GAAAA,CAAI,GAAA;;;;AAK7D,IAAA,OAAOE,oBAAAA,CAAqBF,GAAAA,EAAK,CAACM,OAAAA,GAChCzD,2BAAAA,CAA4B;AAAE,YAAA,GAAGyD,OAAO;AAAErD,YAAAA;AAA0B,SAAA,CAAA,CAAA;AAExE;;;;;"}
@@ -38,7 +38,7 @@ const getRequiredAttributes = (allAttributes)=>{
38
38
  return true;
39
39
  };
40
40
  // Get all the route methods
41
- const routeMethods = routeInfo.routes.map((route)=>route.method);
41
+ const routeMethods = new Set(routeInfo.routes.map((route)=>route.method));
42
42
  const attributesToOmit = [
43
43
  'createdAt',
44
44
  'updatedAt',
@@ -51,7 +51,7 @@ const getRequiredAttributes = (allAttributes)=>{
51
51
  // Get a list of required attribute names
52
52
  const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);
53
53
  // Build the request schemas when the route has POST or PUT methods
54
- if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {
54
+ if (routeMethods.has('POST') || routeMethods.has('PUT')) {
55
55
  // Build localization requests schemas
56
56
  // Build the request schema
57
57
  Object.assign(schemas, {
@@ -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 = ({\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,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AA;AACjD,CAAA;AAEA,MAAM4C,+BAA+B,CAACC,GAAAA,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;;;;"}
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 = new Set(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.has('POST') || routeMethods.has('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","Set","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","has","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,CAACK,aAAaC;AAChB,SAAA;QAEA,OAAO,IAAA;AACT,IAAA,CAAA;;IAGA,MAAMI,YAAAA,GAAe,IAAIC,GAAAA,CAAIf,SAAAA,CAAUgB,MAAM,CAACC,GAAG,CAAC,CAACC,KAAAA,GAAsBA,KAAAA,CAAMC,MAAM,CAAA,CAAA;AAErF,IAAA,MAAMC,gBAAAA,GAAmB;AACvB,QAAA,WAAA;AACA,QAAA,WAAA;AACA,QAAA,aAAA;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EAAM,QAAA;YACNd,UAAAA,EAAY;gBACVe,IAAAA,EAAM;oBACJS,IAAAA,EAAM,CAAC,qBAAqB,EAAE/B,QAAAA,CAAAA;AAChC,iBAAA;gBACAgC,IAAAA,EAAM;oBAAEX,IAAAA,EAAM;AAAS;AACzB;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AAAE,QAAA,GAAGtB,OAAO;AAAE,QAAA,GAAGD;AAAuB,KAAA;AACjD,CAAA;AAEA,MAAM6C,+BAA+B,CAACC,GAAAA,GAAAA;AACpC,IAAA,MAAM/C,4BAA4B,IAAIgD,GAAAA,EAAAA;AAEtCC,IAAAA,oBAAAA,CAAqBF,KAAK,CAAC,EAAEG,GAAG,EAAEnD,UAAU,EAAE,GAAA;QAC5CC,yBAAAA,CAA0BmD,GAAG,CAACD,GAAAA,EAAK9C,UAAAA,CAAWL,UAAAA,CAAAA,CAAAA;AAC9C,QAAA,OAAO,EAAC;AACV,IAAA,CAAA,CAAA;IAEA,OAAOC,yBAAAA;AACT;AAEA,MAAMoD,oBAAAA,GAAuB,CAC3BL,GAAAA,EACA/C,yBAAAA,GAA4B8C,6BAA6BC,GAAAA,CAAI,GAAA;;;;AAK7D,IAAA,OAAOE,oBAAAA,CAAqBF,GAAAA,EAAK,CAACM,OAAAA,GAChCzD,2BAAAA,CAA4B;AAAE,YAAA,GAAGyD,OAAO;AAAErD,YAAAA;AAA0B,SAAA,CAAA,CAAA;AAExE;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-documentation",
3
- "version": "5.57.0",
3
+ "version": "5.59.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.57.0",
66
+ "@strapi/admin": "5.59.0",
67
67
  "@strapi/design-system": "2.2.4",
68
68
  "@strapi/icons": "2.2.4",
69
- "@strapi/utils": "5.57.0",
69
+ "@strapi/utils": "5.59.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.57.0",
86
- "@strapi/strapi": "5.57.0",
87
- "@strapi/types": "5.57.0",
85
+ "@strapi/admin-test-utils": "5.59.0",
86
+ "@strapi/strapi": "5.59.0",
87
+ "@strapi/types": "5.59.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",