@strapi/plugin-documentation 5.33.2 → 5.33.4

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.
@@ -129,7 +129,14 @@ const getRequiredAttributes = (allAttributes)=>{
129
129
  },
130
130
  properties: {
131
131
  id: {
132
- type: 'number'
132
+ oneOf: [
133
+ {
134
+ type: 'string'
135
+ },
136
+ {
137
+ type: 'number'
138
+ }
139
+ ]
133
140
  },
134
141
  documentId: {
135
142
  type: 'string'
@@ -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: { type: 'number' },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, { didAddStrapiComponentsToSchemas }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst buildComponentSchema = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getAllSchemasForContentType);\n};\n\nexport default buildComponentSchema;\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","documentId","buildComponentSchema","api","loopContentTypeNames"],"mappings":";;;;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAe,CAAA;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAI,CAAA,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B;AACF;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,8BAA8B,CAAC,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,EAAW,GAAA;;AAEjF,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAWJ,CAAAA,UAAAA,CAAAA;;IAG5B,MAAMK,+BAAAA,GAAkC,CAACC,UAAoBC,EAAAA,MAAAA,GAAAA;AAC3D,QAAA,IAAI,CAACC,MAAAA,CAAOC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,IAAM,EAAA;AAAS,iBAAA;gBACrBoB,UAAY,EAAA;oBAAEpB,IAAM,EAAA;AAAS,iBAAA;AAC7B,gBAAA,GAAGG,sBAAsB3B,UAAY,EAAA;AAAEM,oBAAAA;iBAAkC;AAC3E;AACF,SAAA;AAEA,QAAA,CAAC,CAAGF,EAAAA,QAAAA,CAAS,QAAQ,CAAC,GAAG;YACvBoB,IAAM,EAAA,QAAA;YACNb,UAAY,EAAA;gBACVc,IAAM,EAAA;oBACJS,IAAM,EAAA,CAAC,qBAAqB,EAAE9B,QAAU,CAAA;AAC1C,iBAAA;gBACA+B,IAAM,EAAA;oBAAEX,IAAM,EAAA;AAAS;AACzB;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AAAE,QAAA,GAAGrB,OAAO;AAAE,QAAA,GAAGD;AAAuB,KAAA;AACjD,CAAA;AAEA,MAAM2C,uBAAuB,CAACC,GAAAA,GAAAA;;;;AAI5B,IAAA,OAAOC,qBAAqBD,GAAKhD,EAAAA,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 = ({ 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,aAAe,CAAA;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAI,CAAA,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B;AACF;IAEA,OAAOD,kBA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F;AACF;AACF;AACF,SAAA,CAAA;AACF;AAEA,IAAA,MAAM9B,qBAAqBF,qBAAsBQ,CAAAA,UAAAA,CAAAA;;IAEjDS,MAAOc,CAAAA,MAAM,CAACpB,OAAS,EAAA;QACrB,CAAC,CAAA,EAAGC,QAAU,CAAA,CAAA,GAAG;YACfoB,IAAM,EAAA,QAAA;YACN,GAAI9B,kBAAAA,CAAmBgC,MAAM,IAAI;gBAAE9B,QAAUF,EAAAA;aAAoB;YACjEiB,UAAY,EAAA;gBACVgC,EAAI,EAAA;oBAAEC,KAAO,EAAA;AAAC,wBAAA;4BAAEpB,IAAM,EAAA;AAAS,yBAAA;AAAG,wBAAA;4BAAEA,IAAM,EAAA;AAAS;AAAE;AAAC,iBAAA;gBACtDqB,UAAY,EAAA;oBAAErB,IAAM,EAAA;AAAS,iBAAA;AAC7B,gBAAA,GAAGG,sBAAsB3B,UAAY,EAAA;AAAEM,oBAAAA;iBAAkC;AAC3E;AACF,SAAA;AAEA,QAAA,CAAC,CAAGF,EAAAA,QAAAA,CAAS,QAAQ,CAAC,GAAG;YACvBoB,IAAM,EAAA,QAAA;YACNb,UAAY,EAAA;gBACVc,IAAM,EAAA;oBACJS,IAAM,EAAA,CAAC,qBAAqB,EAAE9B,QAAU,CAAA;AAC1C,iBAAA;gBACA+B,IAAM,EAAA;oBAAEX,IAAM,EAAA;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,GAAKjD,EAAAA,2BAAAA,CAAAA;AACnC;;;;"}
@@ -127,7 +127,14 @@ const getRequiredAttributes = (allAttributes)=>{
127
127
  },
128
128
  properties: {
129
129
  id: {
130
- type: 'number'
130
+ oneOf: [
131
+ {
132
+ type: 'string'
133
+ },
134
+ {
135
+ type: 'number'
136
+ }
137
+ ]
131
138
  },
132
139
  documentId: {
133
140
  type: 'string'
@@ -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: { type: 'number' },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, { didAddStrapiComponentsToSchemas }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst buildComponentSchema = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getAllSchemasForContentType);\n};\n\nexport default buildComponentSchema;\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","documentId","buildComponentSchema","api","loopContentTypeNames"],"mappings":";;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAe,CAAA;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAI,CAAA,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B;AACF;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,8BAA8B,CAAC,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,EAAW,GAAA;;AAEjF,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAWJ,CAAAA,UAAAA,CAAAA;;IAG5B,MAAMK,+BAAAA,GAAkC,CAACC,UAAoBC,EAAAA,MAAAA,GAAAA;AAC3D,QAAA,IAAI,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAW,CAAA,IAAA,CAACC,MAAOC,CAAAA,IAAI,CAACF,MAAAA,CAAOG,UAAU,CAAA,EAAI,OAAO,KAAA;;QAGrET,sBAAyB,GAAA;AACvB,YAAA,GAAGA,sBAAsB;AACzB,YAAA,CAACK,aAAaC;AAChB,SAAA;QAEA,OAAO,IAAA;AACT,KAAA;;IAGA,MAAMI,YAAAA,GAAeb,UAAUc,MAAM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UAAY,EAAA;gBACVc,IAAM,EAAA;oBACJS,IAAM,EAAA,CAAC,qBAAqB,EAAE9B,QAAU,CAAA;AAC1C,iBAAA;gBACA+B,IAAM,EAAA;oBAAEX,IAAM,EAAA;AAAS;AACzB;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AAAE,QAAA,GAAGrB,OAAO;AAAE,QAAA,GAAGD;AAAuB,KAAA;AACjD,CAAA;AAEA,MAAM2C,uBAAuB,CAACC,GAAAA,GAAAA;;;;AAI5B,IAAA,OAAOC,qBAAqBD,GAAKhD,EAAAA,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 = ({ 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,aAAe,CAAA;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAI,CAAA,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B;AACF;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,8BAA8B,CAAC,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,EAAW,GAAA;;AAEjF,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAWJ,CAAAA,UAAAA,CAAAA;;IAG5B,MAAMK,+BAAAA,GAAk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E9B,QAAUF,EAAAA;aAAoB;YACjEiB,UAAY,EAAA;gBACVgC,EAAI,EAAA;oBAAEC,KAAO,EAAA;AAAC,wBAAA;4BAAEpB,IAAM,EAAA;AAAS,yBAAA;AAAG,wBAAA;4BAAEA,IAAM,EAAA;AAAS;AAAE;AAAC,iBAAA;gBACtDqB,UAAY,EAAA;oBAAErB,IAAM,EAAA;AAAS,iBAAA;AAC7B,gBAAA,GAAGG,sBAAsB3B,UAAY,EAAA;AAAEM,oBAAAA;iBAAkC;AAC3E;AACF,SAAA;AAEA,QAAA,CAAC,CAAGF,EAAAA,QAAAA,CAAS,QAAQ,CAAC,GAAG;YACvBoB,IAAM,EAAA,QAAA;YACNb,UAAY,EAAA;gBACVc,IAAM,EAAA;oBACJS,IAAM,EAAA,CAAC,qBAAqB,EAAE9B,QAAU,CAAA;AAC1C,iBAAA;gBACA+B,IAAM,EAAA;oBAAEX,IAAM,EAAA;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,GAAKjD,EAAAA,2BAAAA,CAAAA;AACnC;;;;"}
@@ -149,7 +149,14 @@ var pascalCase = require('./pascal-case.js');
149
149
  properties: {
150
150
  ...isRequest ? {} : {
151
151
  id: {
152
- type: 'number'
152
+ oneOf: [
153
+ {
154
+ type: 'string'
155
+ },
156
+ {
157
+ type: 'number'
158
+ }
159
+ ]
153
160
  }
154
161
  },
155
162
  ...cleanSchemaAttributes(componentAttributes, {
@@ -183,7 +190,14 @@ var pascalCase = require('./pascal-case.js');
183
190
  properties: {
184
191
  ...isRequest ? {} : {
185
192
  id: {
186
- type: 'number'
193
+ oneOf: [
194
+ {
195
+ type: 'string'
196
+ },
197
+ {
198
+ type: 'number'
199
+ }
200
+ ]
187
201
  }
188
202
  },
189
203
  __component: {
@@ -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) => {\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: { 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: { 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","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","oneOf","getSchemaData","relation","includes","target","has","set","targetAttributes","Error"],"mappings":";;;;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAqB,GAAA,CAAA,EAAGC,UAAWH,CAAAA,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAO,EAAA;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAoB,CAAA,CAAA;AACrD;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;AAIC,IACKE,MAAAA,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,MAAOC,CAAAA,IAAI,CAACR,UAAa,CAAA,CAAA;QAC1C,MAAMS,SAAAA,GAAYT,UAAU,CAACM,IAAK,CAAA;AAElC,QAAA,OAAQG,UAAUC,IAAI;YACpB,KAAK,UAAA;AAAY,gBAAA;AACf,oBAAA,IAAI,CAACP,SAAW,EAAA;AACd,wBAAA;AACF;oBAEAE,gBAAgB,CAACC,KAAK,GAAG;wBAAEI,IAAM,EAAA,QAAA;wBAAUC,MAAQ,E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EAAEhD,UAAU;AAExEK,oBAAAA,gBAAgB,CAACC,IAAK,CAAA,GAAGuC,aACvBJ,CAAAA,gBAAAA,EACA1C,sBAAsBoD,gBAAkB,EAAA;AACtClD,wBAAAA,OAAAA;AACAE,wBAAAA,SAAAA;AACAC,wBAAAA;AACF,qBAAA,CAAA,CAAA;AAGF,oBAAA;AACF;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIgD,MAAM,CAAC,aAAa,EAAE3C,SAAUC,CAAAA,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF;AACF;AACF;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 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) => {\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,kBAAqB,GAAA,CAAA,EAAGC,UAAWH,CAAAA,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAO,EAAA;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAoB,CAAA,CAAA;AACrD;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;AAIC,IACKE,MAAAA,qBAAAA,GAAwB,CAC5BC,UAAAA,EACA,EAAEC,OAAAA,GAAU,IAAIC,GAAAA,EAAK,EAAEC,SA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A;AACX,yBAAA;wBAEAP,gBAAgB,CAACC,IAAK,CAAA,GAAGoC,gBACrB,GAAA;4BAAEhC,IAAM,EAAA,OAAA;4BAASmB,KAAOe,EAAAA;yBACxBA,GAAAA,SAAAA;AACJ,wBAAA;AACF;AAEA,oBAAA,IAAI,EAAE,QAAYnC,IAAAA,SAAQ,KAAM,CAACA,SAAAA,CAAUuC,MAAM,IAAI/C,OAAQgD,CAAAA,GAAG,CAACxC,SAAAA,CAAUuC,MAAM,CAAG,EAAA;AAClF3C,wBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CAAcH,kBAAkB,EAAC,CAAA;AAE1D,wBAAA;AACF;AAEAzC,oBAAAA,OAAAA,CAAQiD,GAAG,CAACzC,SAAUuC,CAAAA,MAAM,EAAE,IAAA,CAAA;AAC9B,oBAAA,MAAMG,mBAAmBjC,MAAOuB,CAAAA,WAAW,CAAChC,SAAUuC,CAAAA,MAAM,EAAEhD,UAAU;AAExEK,oBAAAA,gBAAgB,CAACC,IAAK,CAAA,GAAGuC,aACvBH,CAAAA,gBAAAA,EACA3C,sBAAsBoD,gBAAkB,EAAA;AACtClD,wBAAAA,OAAAA;AACAE,wBAAAA,SAAAA;AACAC,wBAAAA;AACF,qBAAA,CAAA,CAAA;AAGF,oBAAA;AACF;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIgD,MAAM,CAAC,aAAa,EAAE3C,SAAUC,CAAAA,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF;AACF;AACF;IAEA,OAAOL,gBAAAA;AACT;;;;"}
@@ -147,7 +147,14 @@ import pascalCase from './pascal-case.mjs';
147
147
  properties: {
148
148
  ...isRequest ? {} : {
149
149
  id: {
150
- type: 'number'
150
+ oneOf: [
151
+ {
152
+ type: 'string'
153
+ },
154
+ {
155
+ type: 'number'
156
+ }
157
+ ]
151
158
  }
152
159
  },
153
160
  ...cleanSchemaAttributes(componentAttributes, {
@@ -181,7 +188,14 @@ import pascalCase from './pascal-case.mjs';
181
188
  properties: {
182
189
  ...isRequest ? {} : {
183
190
  id: {
184
- type: 'number'
191
+ oneOf: [
192
+ {
193
+ type: 'string'
194
+ },
195
+ {
196
+ type: 'number'
197
+ }
198
+ ]
185
199
  }
186
200
  },
187
201
  __component: {
@@ -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) => {\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: { 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: { 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","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","oneOf","getSchemaData","relation","includes","target","has","set","targetAttributes","Error"],"mappings":";;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAqB,GAAA,CAAA,EAAGC,UAAWH,CAAAA,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAO,EAAA;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAoB,CAAA,CAAA;AACrD;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;AAIC,IACKE,MAAAA,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,MAAOC,CAAAA,IAAI,CAACR,UAAa,CAAA,CAAA;QAC1C,MAAMS,SAAAA,GAAYT,UAAU,CAACM,IAAK,CAAA;AAElC,QAAA,OAAQG,UAAUC,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AEAxC,oBAAAA,OAAAA,CAAQiD,GAAG,CAACzC,SAAUuC,CAAAA,MAAM,EAAE,IAAA,CAAA;AAC9B,oBAAA,MAAMG,mBAAmBjC,MAAOsB,CAAAA,WAAW,CAAC/B,SAAUuC,CAAAA,MAAM,EAAEhD,UAAU;AAExEK,oBAAAA,gBAAgB,CAACC,IAAK,CAAA,GAAGuC,aACvBJ,CAAAA,gBAAAA,EACA1C,sBAAsBoD,gBAAkB,EAAA;AACtClD,wBAAAA,OAAAA;AACAE,wBAAAA,SAAAA;AACAC,wBAAAA;AACF,qBAAA,CAAA,CAAA;AAGF,oBAAA;AACF;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIgD,MAAM,CAAC,aAAa,EAAE3C,SAAUC,CAAAA,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF;AACF;AACF;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 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) => {\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,kBAAqB,GAAA,CAAA,EAAGC,UAAWH,CAAAA,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAO,EAAA;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAA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19
+ {
20
+ type: 'string'
21
+ },
22
+ {
23
+ type: 'number'
24
+ }
25
+ ]
19
26
  },
20
27
  documentId: {
21
28
  type: 'string'
@@ -29,7 +36,14 @@
29
36
  type: 'object',
30
37
  properties: {
31
38
  id: {
32
- type: 'number'
39
+ oneOf: [
40
+ {
41
+ type: 'string'
42
+ },
43
+ {
44
+ type: 'number'
45
+ }
46
+ ]
33
47
  },
34
48
  documentId: {
35
49
  type: 'string'
@@ -1 +1 @@
1
- {"version":3,"file":"get-schema-data.js","sources":["../../../../../server/src/services/helpers/utils/get-schema-data.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\n/**\n * @description Determines the format of the data response\n *\n * @param {boolean} isListOfEntities - Checks for a multiple entities\n * @param {object} attributes - The attributes found on a contentType\n\n * @returns object | array of attributes\n */\nexport default (\n isListOfEntities: boolean,\n attributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>\n): OpenAPIV3.SchemaObject => {\n if (isListOfEntities) {\n return {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { type: 'number' },\n documentId: { type: 'string' },\n ...attributes,\n },\n },\n };\n }\n\n return {\n type: 'object',\n properties: {\n id: { type: 'number' },\n documentId: { type: 'string' },\n ...attributes,\n },\n };\n};\n"],"names":["isListOfEntities","attributes","type","items","properties","id","documentId"],"mappings":";;AAEA;;;;;;;IAQA,oBAAe,CAAA,CACbA,gBACAC,EAAAA,UAAAA,GAAAA;AAEA,IAAA,IAAID,gBAAkB,EAAA;QACpB,OAAO;YACLE,IAAM,EAAA,OAAA;YACNC,KAAO,EAAA;gBACLD,IAAM,EAAA,QAAA;gBACNE,UAAY,EAAA;oBACVC,EAAI,EAAA;wBAAEH,IAAM,EAAA;AAAS,qBAAA;oBACrBI,UAAY,EAAA;wBAAEJ,IAAM,EAAA;AAAS,qBAAA;AAC7B,oBAAA,GAAGD;AACL;AACF;AACF,SAAA;AACF;IAEA,OAAO;QACLC,IAAM,EAAA,QAAA;QACNE,UAAY,EAAA;YACVC,EAAI,EAAA;gBAAEH,IAAM,EAAA;AAAS,aAAA;YACrBI,UAAY,EAAA;gBAAEJ,IAAM,EAAA;AAAS,aAAA;AAC7B,YAAA,GAAGD;AACL;AACF,KAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"get-schema-data.js","sources":["../../../../../server/src/services/helpers/utils/get-schema-data.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\n/**\n * @description Determines the format of the data response\n *\n * @param {boolean} isListOfEntities - Checks for a multiple entities\n * @param {object} attributes - The attributes found on a contentType\n\n * @returns object | array of attributes\n */\nexport default (\n isListOfEntities: boolean,\n attributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>\n): OpenAPIV3.SchemaObject => {\n if (isListOfEntities) {\n return {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...attributes,\n },\n },\n };\n }\n\n return {\n type: 'object',\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...attributes,\n },\n };\n};\n"],"names":["isListOfEntities","attributes","type","items","properties","id","oneOf","documentId"],"mappings":";;AAEA;;;;;;;IAQA,oBAAe,CAAA,CACbA,gBACAC,EAAAA,UAAAA,GAAAA;AAEA,IAAA,IAAID,gBAAkB,EAAA;QACpB,OAAO;YACLE,IAAM,EAAA,OAAA;YACNC,KAAO,EAAA;gBACLD,IAAM,EAAA,QAAA;gBACNE,UAAY,EAAA;oBACVC,EAAI,EAAA;wBAAEC,KAAO,EAAA;AAAC,4BAAA;gCAAEJ,IAAM,EAAA;AAAS,6BAAA;AAAG,4BAAA;gCAAEA,IAAM,EAAA;AAAS;AAAE;AAAC,qBAAA;oBACtDK,UAAY,EAAA;wBAAEL,IAAM,EAAA;AAAS,qBAAA;AAC7B,oBAAA,GAAGD;AACL;AACF;AACF,SAAA;AACF;IAEA,OAAO;QACLC,IAAM,EAAA,QAAA;QACNE,UAAY,EAAA;YACVC,EAAI,EAAA;gBAAEC,KAAO,EAAA;AAAC,oBAAA;wBAAEJ,IAAM,EAAA;AAAS,qBAAA;AAAG,oBAAA;wBAAEA,IAAM,EAAA;AAAS;AAAE;AAAC,aAAA;YACtDK,UAAY,EAAA;gBAAEL,IAAM,EAAA;AAAS,aAAA;AAC7B,YAAA,GAAGD;AACL;AACF,KAAA;AACF,CAAA;;;;"}
@@ -13,7 +13,14 @@
13
13
  type: 'object',
14
14
  properties: {
15
15
  id: {
16
- type: 'number'
16
+ oneOf: [
17
+ {
18
+ type: 'string'
19
+ },
20
+ {
21
+ type: 'number'
22
+ }
23
+ ]
17
24
  },
18
25
  documentId: {
19
26
  type: 'string'
@@ -27,7 +34,14 @@
27
34
  type: 'object',
28
35
  properties: {
29
36
  id: {
30
- type: 'number'
37
+ oneOf: [
38
+ {
39
+ type: 'string'
40
+ },
41
+ {
42
+ type: 'number'
43
+ }
44
+ ]
31
45
  },
32
46
  documentId: {
33
47
  type: 'string'
@@ -1 +1 @@
1
- {"version":3,"file":"get-schema-data.mjs","sources":["../../../../../server/src/services/helpers/utils/get-schema-data.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\n/**\n * @description Determines the format of the data response\n *\n * @param {boolean} isListOfEntities - Checks for a multiple entities\n * @param {object} attributes - The attributes found on a contentType\n\n * @returns object | array of attributes\n */\nexport default (\n isListOfEntities: boolean,\n attributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>\n): OpenAPIV3.SchemaObject => {\n if (isListOfEntities) {\n return {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { type: 'number' },\n documentId: { type: 'string' },\n ...attributes,\n },\n },\n };\n }\n\n return {\n type: 'object',\n properties: {\n id: { type: 'number' },\n documentId: { type: 'string' },\n ...attributes,\n },\n };\n};\n"],"names":["isListOfEntities","attributes","type","items","properties","id","documentId"],"mappings":"AAEA;;;;;;;IAQA,oBAAe,CAAA,CACbA,gBACAC,EAAAA,UAAAA,GAAAA;AAEA,IAAA,IAAID,gBAAkB,EAAA;QACpB,OAAO;YACLE,IAAM,EAAA,OAAA;YACNC,KAAO,EAAA;gBACLD,IAAM,EAAA,QAAA;gBACNE,UAAY,EAAA;oBACVC,EAAI,EAAA;wBAAEH,IAAM,EAAA;AAAS,qBAAA;oBACrBI,UAAY,EAAA;wBAAEJ,IAAM,EAAA;AAAS,qBAAA;AAC7B,oBAAA,GAAGD;AACL;AACF;AACF,SAAA;AACF;IAEA,OAAO;QACLC,IAAM,EAAA,QAAA;QACNE,UAAY,EAAA;YACVC,EAAI,EAAA;gBAAEH,IAAM,EAAA;AAAS,aAAA;YACrBI,UAAY,EAAA;gBAAEJ,IAAM,EAAA;AAAS,aAAA;AAC7B,YAAA,GAAGD;AACL;AACF,KAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"get-schema-data.mjs","sources":["../../../../../server/src/services/helpers/utils/get-schema-data.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\n/**\n * @description Determines the format of the data response\n *\n * @param {boolean} isListOfEntities - Checks for a multiple entities\n * @param {object} attributes - The attributes found on a contentType\n\n * @returns object | array of attributes\n */\nexport default (\n isListOfEntities: boolean,\n attributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>\n): OpenAPIV3.SchemaObject => {\n if (isListOfEntities) {\n return {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...attributes,\n },\n },\n };\n }\n\n return {\n type: 'object',\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...attributes,\n },\n };\n};\n"],"names":["isListOfEntities","attributes","type","items","properties","id","oneOf","documentId"],"mappings":"AAEA;;;;;;;IAQA,oBAAe,CAAA,CACbA,gBACAC,EAAAA,UAAAA,GAAAA;AAEA,IAAA,IAAID,gBAAkB,EAAA;QACpB,OAAO;YACLE,IAAM,EAAA,OAAA;YACNC,KAAO,EAAA;gBACLD,IAAM,EAAA,QAAA;gBACNE,UAAY,EAAA;oBACVC,EAAI,EAAA;wBAAEC,KAAO,EAAA;AAAC,4BAAA;gCAAEJ,IAAM,EAAA;AAAS,6BAAA;AAAG,4BAAA;gCAAEA,IAAM,EAAA;AAAS;AAAE;AAAC,qBAAA;oBACtDK,UAAY,EAAA;wBAAEL,IAAM,EAAA;AAAS,qBAAA;AAC7B,oBAAA,GAAGD;AACL;AACF;AACF,SAAA;AACF;IAEA,OAAO;QACLC,IAAM,EAAA,QAAA;QACNE,UAAY,EAAA;YACVC,EAAI,EAAA;gBAAEC,KAAO,EAAA;AAAC,oBAAA;wBAAEJ,IAAM,EAAA;AAAS,qBAAA;AAAG,oBAAA;wBAAEA,IAAM,EAAA;AAAS;AAAE;AAAC,aAAA;YACtDK,UAAY,EAAA;gBAAEL,IAAM,EAAA;AAAS,aAAA;AAC7B,YAAA,GAAGD;AACL;AACF,KAAA;AACF,CAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/plugin-documentation",
3
- "version": "5.33.2",
3
+ "version": "5.33.4",
4
4
  "description": "Create an OpenAPI Document and visualize your API with SWAGGER UI.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -59,10 +59,10 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@reduxjs/toolkit": "1.9.7",
62
- "@strapi/admin": "5.33.2",
63
- "@strapi/design-system": "2.0.1",
64
- "@strapi/icons": "2.0.1",
65
- "@strapi/utils": "5.33.2",
62
+ "@strapi/admin": "5.33.4",
63
+ "@strapi/design-system": "2.1.2",
64
+ "@strapi/icons": "2.1.2",
65
+ "@strapi/utils": "5.33.4",
66
66
  "bcryptjs": "2.4.3",
67
67
  "cheerio": "^1.0.0",
68
68
  "formik": "2.4.5",
@@ -78,16 +78,16 @@
78
78
  },
79
79
  "devDependencies": {
80
80
  "@apidevtools/swagger-parser": "^10.1.0",
81
- "@strapi/admin-test-utils": "5.33.2",
82
- "@strapi/strapi": "5.33.2",
83
- "@strapi/types": "5.33.2",
81
+ "@strapi/admin-test-utils": "5.33.4",
82
+ "@strapi/strapi": "5.33.4",
83
+ "@strapi/types": "5.33.4",
84
84
  "@testing-library/react": "16.3.0",
85
85
  "@testing-library/user-event": "14.6.1",
86
86
  "@types/fs-extra": "11.0.4",
87
87
  "@types/koa": "2.13.4",
88
88
  "@types/koa-session": "6.4.1",
89
89
  "@types/swagger-ui-dist": "3.30.4",
90
- "koa": "2.16.1",
90
+ "koa": "2.16.3",
91
91
  "koa-body": "6.0.1",
92
92
  "koa-session": "6.4.0",
93
93
  "msw": "1.3.0",