@strapi/plugin-documentation 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282 → 0.0.0-experimental.63624e21eb5b0713345a0cf2f68f1c40eab427bc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/admin/pages/App.js.map +1 -1
- package/dist/admin/pages/App.mjs.map +1 -1
- package/dist/admin/pages/Settings.js +2 -2
- package/dist/admin/pages/Settings.js.map +1 -1
- package/dist/admin/pages/Settings.mjs +2 -2
- package/dist/admin/pages/Settings.mjs.map +1 -1
- package/dist/admin/src/services/api.d.ts +4 -4
- package/dist/admin/translations/ko.json.js +4 -1
- package/dist/admin/translations/ko.json.js.map +1 -1
- package/dist/admin/translations/ko.json.mjs +4 -1
- package/dist/admin/translations/ko.json.mjs.map +1 -1
- package/dist/server/controllers/documentation.js +6 -1
- package/dist/server/controllers/documentation.js.map +1 -1
- package/dist/server/controllers/documentation.mjs +6 -1
- package/dist/server/controllers/documentation.mjs.map +1 -1
- package/dist/server/controllers/index.js.map +1 -1
- package/dist/server/controllers/index.mjs.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/routes/index.js +2 -1
- package/dist/server/routes/index.js.map +1 -1
- package/dist/server/routes/index.mjs +2 -1
- package/dist/server/routes/index.mjs.map +1 -1
- package/dist/server/services/documentation.js +40 -8
- package/dist/server/services/documentation.js.map +1 -1
- package/dist/server/services/documentation.mjs +41 -9
- package/dist/server/services/documentation.mjs.map +1 -1
- package/dist/server/services/helpers/build-component-schema.js +21 -6
- package/dist/server/services/helpers/build-component-schema.js.map +1 -1
- package/dist/server/services/helpers/build-component-schema.mjs +18 -6
- package/dist/server/services/helpers/build-component-schema.mjs.map +1 -1
- package/dist/server/services/helpers/utils/clean-schema-attributes.js +14 -13
- package/dist/server/services/helpers/utils/clean-schema-attributes.js.map +1 -1
- package/dist/server/services/helpers/utils/clean-schema-attributes.mjs +14 -13
- package/dist/server/services/helpers/utils/clean-schema-attributes.mjs.map +1 -1
- package/dist/server/services/helpers/utils/loop-content-type-names.js +1 -0
- package/dist/server/services/helpers/utils/loop-content-type-names.js.map +1 -1
- package/dist/server/services/helpers/utils/loop-content-type-names.mjs +1 -0
- package/dist/server/services/helpers/utils/loop-content-type-names.mjs.map +1 -1
- package/dist/server/services/helpers/utils/query-params.js +11 -1
- package/dist/server/services/helpers/utils/query-params.js.map +1 -1
- package/dist/server/services/helpers/utils/query-params.mjs +11 -1
- package/dist/server/services/helpers/utils/query-params.mjs.map +1 -1
- package/dist/server/services/index.js.map +1 -1
- package/dist/server/services/index.mjs.map +1 -1
- package/dist/server/services/override.js +19 -3
- package/dist/server/services/override.js.map +1 -1
- package/dist/server/services/override.mjs +19 -3
- package/dist/server/services/override.mjs.map +1 -1
- package/dist/server/src/config/index.d.ts +1 -1
- package/dist/server/src/controllers/documentation.d.ts.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +5 -2
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts +4 -3
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/documentation.d.ts +35 -0
- package/dist/server/src/services/documentation.d.ts.map +1 -1
- package/dist/server/src/services/helpers/build-component-schema.d.ts +3 -1
- package/dist/server/src/services/helpers/build-component-schema.d.ts.map +1 -1
- package/dist/server/src/services/helpers/index.d.ts +2 -2
- package/dist/server/src/services/helpers/index.d.ts.map +1 -1
- package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts +2 -2
- package/dist/server/src/services/helpers/utils/clean-schema-attributes.d.ts.map +1 -1
- package/dist/server/src/services/helpers/utils/loop-content-type-names.d.ts.map +1 -1
- package/dist/server/src/services/helpers/utils/query-params.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +5 -4
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/override.d.ts +16 -0
- package/dist/server/src/services/override.d.ts.map +1 -1
- package/dist/server/src/types/controllers.d.ts +26 -0
- package/dist/server/src/types/controllers.d.ts.map +1 -0
- package/dist/server/src/types/services.d.ts +47 -0
- package/dist/server/src/types/services.d.ts.map +1 -0
- package/dist/server/src/types.d.ts +1 -0
- package/dist/server/src/types.d.ts.map +1 -1
- package/package.json +28 -16
|
@@ -22,7 +22,7 @@ const getRequiredAttributes = (allAttributes)=>{
|
|
|
22
22
|
* @property {object} apiInfo.routeInfo - The routes for the api
|
|
23
23
|
*
|
|
24
24
|
* @returns {object} Open API schemas
|
|
25
|
-
*/ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName })=>{
|
|
25
|
+
*/ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName, relationTargetSchemaNames })=>{
|
|
26
26
|
// Store response and request schemas in an object
|
|
27
27
|
let strapiComponentSchemas = {};
|
|
28
28
|
const schemas = {};
|
|
@@ -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.
|
|
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, {
|
|
@@ -140,6 +140,7 @@ const getRequiredAttributes = (allAttributes)=>{
|
|
|
140
140
|
type: 'string'
|
|
141
141
|
},
|
|
142
142
|
...cleanSchemaAttributes(attributes, {
|
|
143
|
+
relationTargetSchemaNames,
|
|
143
144
|
didAddStrapiComponentsToSchemas
|
|
144
145
|
})
|
|
145
146
|
}
|
|
@@ -161,12 +162,23 @@ const getRequiredAttributes = (allAttributes)=>{
|
|
|
161
162
|
...strapiComponentSchemas
|
|
162
163
|
};
|
|
163
164
|
};
|
|
164
|
-
const
|
|
165
|
+
const getRelationTargetSchemaNames = (api)=>{
|
|
166
|
+
const relationTargetSchemaNames = new Map();
|
|
167
|
+
loopContentTypeNames(api, ({ uid, uniqueName })=>{
|
|
168
|
+
relationTargetSchemaNames.set(uid, pascalCase(uniqueName));
|
|
169
|
+
return {};
|
|
170
|
+
});
|
|
171
|
+
return relationTargetSchemaNames;
|
|
172
|
+
};
|
|
173
|
+
const buildComponentSchema = (api, relationTargetSchemaNames = getRelationTargetSchemaNames(api))=>{
|
|
165
174
|
// A reusable loop for building paths and component schemas
|
|
166
175
|
// Uses the api param to build a new set of params for each content type
|
|
167
176
|
// Passes these new params to the function provided
|
|
168
|
-
return loopContentTypeNames(api, getAllSchemasForContentType
|
|
177
|
+
return loopContentTypeNames(api, (apiInfo)=>getAllSchemasForContentType({
|
|
178
|
+
...apiInfo,
|
|
179
|
+
relationTargetSchemaNames
|
|
180
|
+
}));
|
|
169
181
|
};
|
|
170
182
|
|
|
171
|
-
export { buildComponentSchema as default };
|
|
183
|
+
export { buildComponentSchema as default, getRelationTargetSchemaNames };
|
|
172
184
|
//# sourceMappingURL=build-component-schema.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-component-schema.mjs","sources":["../../../../server/src/services/helpers/build-component-schema.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { Core, Struct } from '@strapi/types';\n\nimport cleanSchemaAttributes from './utils/clean-schema-attributes';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport pascalCase from './utils/pascal-case';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\nconst getRequiredAttributes = (allAttributes: Struct.SchemaAttributes) => {\n const requiredAttributes: string[] = [];\n\n for (const key in allAttributes) {\n if (allAttributes[key].required) {\n requiredAttributes.push(key);\n }\n }\n\n return requiredAttributes;\n};\n\n/**\n * @description Get all open api schema objects for a given content type\n *\n * @param {object} apiInfo\n * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name\n * @property {object} apiInfo.attributes - Attributes on content type\n * @property {object} apiInfo.routeInfo - The routes for the api\n *\n * @returns {object} Open API schemas\n */\nconst getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }: ApiInfo) => {\n // Store response and request schemas in an object\n let strapiComponentSchemas = {};\n const schemas: OpenAPIV3.ComponentsObject = {};\n const typeName = pascalCase(uniqueName);\n\n // adds a ComponentSchema to the Schemas so it can be used as Ref\n const didAddStrapiComponentsToSchemas = (schemaName: string, schema: OpenAPIV3.SchemaObject) => {\n if (!Object.keys(schema) || !Object.keys(schema.properties!)) return false;\n\n // Add the Strapi components to the schema\n strapiComponentSchemas = {\n ...strapiComponentSchemas,\n [schemaName]: schema,\n };\n\n return true;\n };\n\n // Get all the route methods\n const routeMethods = routeInfo.routes.map((route: Core.Route) => route.method);\n\n const attributesToOmit = [\n 'createdAt',\n 'updatedAt',\n 'publishedAt',\n 'publishedBy',\n 'updatedBy',\n 'createdBy',\n ];\n\n const attributesForRequest = _.omit(attributes, attributesToOmit);\n // Get a list of required attribute names\n const requiredRequestAttributes = getRequiredAttributes(attributesForRequest);\n // Build the request schemas when the route has POST or PUT methods\n if (routeMethods.includes('POST') || routeMethods.includes('PUT')) {\n // Build localization requests schemas\n\n // Build the request schema\n Object.assign(schemas, {\n [`${typeName}Request`]: {\n type: 'object',\n required: ['data'],\n properties: {\n data: {\n ...(requiredRequestAttributes.length && { required: requiredRequestAttributes }),\n type: 'object',\n properties: cleanSchemaAttributes(attributesForRequest, {\n isRequest: true,\n didAddStrapiComponentsToSchemas,\n }),\n },\n },\n },\n });\n }\n\n // Check for routes that need to return a list\n const hasListOfEntities = routeInfo.routes.filter((route: Core.Route) =>\n hasFindMethod(route.handler)\n ).length;\n\n if (hasListOfEntities) {\n // Build the list response schema\n Object.assign(schemas, {\n [`${typeName}ListResponse`]: {\n type: 'object',\n properties: {\n data: {\n type: 'array',\n items: {\n $ref: `#/components/schemas/${typeName}`,\n },\n },\n meta: {\n type: 'object',\n properties: {\n pagination: {\n type: 'object',\n properties: {\n page: { type: 'integer' },\n pageSize: { type: 'integer', minimum: 25 },\n pageCount: { type: 'integer', maximum: 1 },\n total: { type: 'integer' },\n },\n },\n },\n },\n },\n },\n });\n }\n\n const requiredAttributes = getRequiredAttributes(attributes);\n // Build the response schema\n Object.assign(schemas, {\n [`${typeName}`]: {\n type: 'object',\n ...(requiredAttributes.length && { required: requiredAttributes }),\n properties: {\n id: { oneOf: [{ type: 'string' }, { type: 'number' }] },\n documentId: { type: 'string' },\n ...cleanSchemaAttributes(attributes, { didAddStrapiComponentsToSchemas }),\n },\n },\n\n [`${typeName}Response`]: {\n type: 'object',\n properties: {\n data: {\n $ref: `#/components/schemas/${typeName}`,\n },\n meta: { type: 'object' },\n },\n },\n });\n\n return { ...schemas, ...strapiComponentSchemas };\n};\n\nconst buildComponentSchema = (api: Api) => {\n // A reusable loop for building paths and component schemas\n // Uses the api param to build a new set of params for each content type\n // Passes these new params to the function provided\n return loopContentTypeNames(api, getAllSchemasForContentType);\n};\n\nexport default buildComponentSchema;\n"],"names":["getRequiredAttributes","allAttributes","requiredAttributes","key","required","push","getAllSchemasForContentType","routeInfo","attributes","uniqueName","strapiComponentSchemas","schemas","typeName","pascalCase","didAddStrapiComponentsToSchemas","schemaName","schema","Object","keys","properties","routeMethods","routes","map","route","method","attributesToOmit","attributesForRequest","_","omit","requiredRequestAttributes","includes","assign","type","data","length","cleanSchemaAttributes","isRequest","hasListOfEntities","filter","hasFindMethod","handler","items","$ref","meta","pagination","page","pageSize","minimum","pageCount","maximum","total","id","oneOf","documentId","buildComponentSchema","api","loopContentTypeNames"],"mappings":";;;;;;AAYA,MAAMA,wBAAwB,CAACC,aAAAA,GAAAA;AAC7B,IAAA,MAAMC,qBAA+B,EAAE;IAEvC,IAAK,MAAMC,OAAOF,aAAAA,CAAe;AAC/B,QAAA,IAAIA,aAAa,CAACE,GAAAA,CAAI,CAACC,QAAQ,EAAE;AAC/BF,YAAAA,kBAAAA,CAAmBG,IAAI,CAACF,GAAAA,CAAAA;AAC1B,QAAA;AACF,IAAA;IAEA,OAAOD,kBAAAA;AACT,CAAA;AAEA;;;;;;;;;IAUA,MAAMI,8BAA8B,CAAC,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,EAAW,GAAA;;AAEjF,IAAA,IAAIC,yBAAyB,EAAC;AAC9B,IAAA,MAAMC,UAAsC,EAAC;AAC7C,IAAA,MAAMC,WAAWC,UAAAA,CAAWJ,UAAAA,CAAAA;;IAG5B,MAAMK,+BAAAA,GAAkC,CAACC,UAAAA,EAAoBC,MAAAA,GAAAA;AAC3D,QAAA,IAAI,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAAA,CAAAA,IAAW,CAACC,MAAAA,CAAOC,IAAI,CAACF,MAAAA,CAAOG,UAAU,CAAA,EAAI,OAAO,KAAA;;QAGrET,sBAAAA,GAAyB;AACvB,YAAA,GAAGA,sBAAsB;AACzB,YAAA,CAACK,aAAaC;AAChB,SAAA;QAEA,OAAO,IAAA;AACT,IAAA,CAAA;;IAGA,MAAMI,YAAAA,GAAeb,UAAUc,MAAM,CAACC,GAAG,CAAC,CAACC,KAAAA,GAAsBA,KAAAA,CAAMC,MAAM,CAAA;AAE7E,IAAA,MAAMC,gBAAAA,GAAmB;AACvB,QAAA,WAAA;AACA,QAAA,WAAA;AACA,QAAA,aAAA;AACA,QAAA,aAAA;AACA,QAAA,WAAA;AACA,QAAA;AACD,KAAA;AAED,IAAA,MAAMC,oBAAAA,GAAuBC,CAA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ChC,iBAAA;gBACA+B,IAAAA,EAAM;oBAAEX,IAAAA,EAAM;AAAS;AACzB;AACF;AACF,KAAA,CAAA;IAEA,OAAO;AAAE,QAAA,GAAGrB,OAAO;AAAE,QAAA,GAAGD;AAAuB,KAAA;AACjD,CAAA;AAEA,MAAM4C,uBAAuB,CAACC,GAAAA,GAAAA;;;;AAI5B,IAAA,OAAOC,qBAAqBD,GAAAA,EAAKjD,2BAAAA,CAAAA;AACnC;;;;"}
|
|
1
|
+
{"version":3,"file":"build-component-schema.mjs","sources":["../../../../server/src/services/helpers/build-component-schema.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { Core, Struct } from '@strapi/types';\n\nimport cleanSchemaAttributes from './utils/clean-schema-attributes';\nimport loopContentTypeNames from './utils/loop-content-type-names';\nimport pascalCase from './utils/pascal-case';\nimport { hasFindMethod } from './utils/routes';\n\nimport type { Api, ApiInfo } from '../../types';\n\nconst getRequiredAttributes = (allAttributes: Struct.SchemaAttributes) => {\n const requiredAttributes: string[] = [];\n\n for (const key in allAttributes) {\n if (allAttributes[key].required) {\n requiredAttributes.push(key);\n }\n }\n\n return requiredAttributes;\n};\n\n/**\n * @description Get all open api schema objects for a given content type\n *\n * @param {object} apiInfo\n * @property {string} apiInfo.uniqueName - Api name | Api name + Content type name\n * @property {object} apiInfo.attributes - Attributes on content type\n * @property {object} apiInfo.routeInfo - The routes for the api\n *\n * @returns {object} Open API schemas\n */\nconst getAllSchemasForContentType = ({\n routeInfo,\n attributes,\n uniqueName,\n relationTargetSchemaNames,\n}: ApiInfo & { relationTargetSchemaNames: Map<string, string> }) => {\n // Store response and request schemas in an object\n let strapiComponentSchemas = {};\n const schemas: OpenAPIV3.ComponentsObject = {};\n const typeName = pascalCase(uniqueName);\n\n // adds a ComponentSchema to the Schemas so it can be used as Ref\n const didAddStrapiComponentsToSchemas = (schemaName: string, schema: OpenAPIV3.SchemaObject) => {\n if (!Object.keys(schema) || !Object.keys(schema.properties!)) return false;\n\n // Add the Strapi components to the schema\n strapiComponentSchemas = {\n ...strapiComponentSchemas,\n [schemaName]: schema,\n };\n\n return true;\n };\n\n // Get all the route methods\n const routeMethods = 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,C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,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;;;;"}
|
|
@@ -18,7 +18,7 @@ var pascalCase = require('./pascal-case.js');
|
|
|
18
18
|
* @description - Converts types found on attributes to OpenAPI acceptable data types
|
|
19
19
|
*
|
|
20
20
|
* @returns Attributes using OpenAPI acceptable data types
|
|
21
|
-
*/ const cleanSchemaAttributes = (attributes, {
|
|
21
|
+
*/ const cleanSchemaAttributes = (attributes, { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas })=>{
|
|
22
22
|
const schemaAttributes = {};
|
|
23
23
|
for (const prop of Object.keys(attributes)){
|
|
24
24
|
const attribute = attributes[prop];
|
|
@@ -160,8 +160,8 @@ var pascalCase = require('./pascal-case.js');
|
|
|
160
160
|
}
|
|
161
161
|
},
|
|
162
162
|
...cleanSchemaAttributes(componentAttributes, {
|
|
163
|
-
typeMap,
|
|
164
163
|
isRequest,
|
|
164
|
+
relationTargetSchemaNames,
|
|
165
165
|
didAddStrapiComponentsToSchemas
|
|
166
166
|
})
|
|
167
167
|
}
|
|
@@ -207,8 +207,8 @@ var pascalCase = require('./pascal-case.js');
|
|
|
207
207
|
]
|
|
208
208
|
},
|
|
209
209
|
...cleanSchemaAttributes(componentAttributes, {
|
|
210
|
-
typeMap,
|
|
211
210
|
isRequest,
|
|
211
|
+
relationTargetSchemaNames,
|
|
212
212
|
didAddStrapiComponentsToSchemas
|
|
213
213
|
})
|
|
214
214
|
}
|
|
@@ -262,7 +262,7 @@ var pascalCase = require('./pascal-case.js');
|
|
|
262
262
|
break;
|
|
263
263
|
}
|
|
264
264
|
schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(imageAttributes, {
|
|
265
|
-
|
|
265
|
+
relationTargetSchemaNames,
|
|
266
266
|
didAddStrapiComponentsToSchemas
|
|
267
267
|
}));
|
|
268
268
|
break;
|
|
@@ -288,17 +288,18 @@ var pascalCase = require('./pascal-case.js');
|
|
|
288
288
|
} : oneOfType;
|
|
289
289
|
break;
|
|
290
290
|
}
|
|
291
|
-
|
|
292
|
-
|
|
291
|
+
const targetSchemaName = 'target' in attribute && attribute.target ? relationTargetSchemaNames?.get(attribute.target) : undefined;
|
|
292
|
+
if (targetSchemaName) {
|
|
293
|
+
const targetSchema = {
|
|
294
|
+
$ref: `#/components/schemas/${targetSchemaName}`
|
|
295
|
+
};
|
|
296
|
+
schemaAttributes[prop] = isListOfEntities ? {
|
|
297
|
+
type: 'array',
|
|
298
|
+
items: targetSchema
|
|
299
|
+
} : targetSchema;
|
|
293
300
|
break;
|
|
294
301
|
}
|
|
295
|
-
|
|
296
|
-
const targetAttributes = strapi.contentType(attribute.target).attributes;
|
|
297
|
-
schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(targetAttributes, {
|
|
298
|
-
typeMap,
|
|
299
|
-
isRequest,
|
|
300
|
-
didAddStrapiComponentsToSchemas
|
|
301
|
-
}));
|
|
302
|
+
schemaAttributes[prop] = getSchemaData(isListOfEntities, {});
|
|
302
303
|
break;
|
|
303
304
|
}
|
|
304
305
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean-schema-attributes.js","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n typeMap?: Map<string, boolean>;\n isRequest?: boolean;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { typeMap = new Map(), isRequest = false, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, { typeMap, didAddStrapiComponentsToSchemas })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n if (!('target' in attribute) || !attribute.target || typeMap.has(attribute.target)) {\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n\n typeMap.set(attribute.target, true);\n const targetAttributes = strapi.contentType(attribute.target).attributes;\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(targetAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n })\n );\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","typeMap","Map","isRequest","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","target","has","set","targetAttributes","Error"],"mappings":";;;;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAAA,GAAqB,CAAA,EAAGC,UAAAA,CAAWH,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAAA,EAAO;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAAA,CAAAA,CAAoB;AACrD,IAAA;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;AAIC,IACD,MAAME,qBAAAA,GAAwB,CAC5BC,UAAAA,EACA,EAAEC,OAAAA,GAAU,IAAIC,GAAAA,EAAK,EAAEC,SAAAA,GAAY,KAAK,EAAEC,+BAA+B,EAAW,GAAA;AAEpF,IAAA,MAAMC,mBAAuF,EAAC;AAE9F,IAAA,KAAK,MAAMC,IAAAA,IAAQC,MAAAA,CAAOC,IAAI,CAACR,UAAAA,CAAAA,CAAa;QAC1C,MAAMS,SAAAA,GAAYT,UAAU,CAACM,IAAAA,CAAK;AAElC,QAAA,OAAQG,UAAUC,IAAI;YACpB,KAAK,UAAA;AAAY,gBAAA;AACf,oBAAA,IAAI,CAACP,SAAAA,EAAW;AACd,wBAAA;AACF,oBAAA;oBAEAE,gB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4BAASmB,KAAAA,EAAOe;yBAAU,GAClCA,SAAAA;AACJ,wBAAA;AACF,oBAAA;AAEA,oBAAA,IAAI,EAAE,QAAA,IAAYnC,SAAQ,KAAM,CAACA,SAAAA,CAAUuC,MAAM,IAAI/C,OAAAA,CAAQgD,GAAG,CAACxC,SAAAA,CAAUuC,MAAM,CAAA,EAAG;AAClF3C,wBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CAAcH,kBAAkB,EAAC,CAAA;AAE1D,wBAAA;AACF,oBAAA;AAEAzC,oBAAAA,OAAAA,CAAQiD,GAAG,CAACzC,SAAAA,CAAUuC,MAAM,EAAE,IAAA,CAAA;AAC9B,oBAAA,MAAMG,mBAAmBjC,MAAAA,CAAOuB,WAAW,CAAChC,SAAAA,CAAUuC,MAAM,EAAEhD,UAAU;AAExEK,oBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CACvBH,gBAAAA,EACA3C,sBAAsBoD,gBAAAA,EAAkB;AACtClD,wBAAAA,OAAAA;AACAE,wBAAAA,SAAAA;AACAC,wBAAAA;AACF,qBAAA,CAAA,CAAA;AAGF,oBAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIgD,MAAM,CAAC,aAAa,EAAE3C,SAAAA,CAAUC,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF,gBAAA;AACF;AACF,IAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"clean-schema-attributes.js","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n isRequest?: boolean;\n relationTargetSchemaNames?: Map<string, string>;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, {\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n const targetSchemaName =\n 'target' in attribute && attribute.target\n ? relationTargetSchemaNames?.get(attribute.target)\n : undefined;\n\n if (targetSchemaName) {\n const targetSchema: OpenAPIV3.ReferenceObject = {\n $ref: `#/components/schemas/${targetSchemaName}`,\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: targetSchema }\n : targetSchema;\n\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","isRequest","relationTargetSchemaNames","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","targetSchemaName","target","get","undefined","targetSchema","Error"],"mappings":";;;;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAAA,GAAqB,CAAA,EAAGC,UAAAA,CAAWH,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAAA,EAAO;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAAA,CAAAA,CAAoB;AACrD,IAAA;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;IAKA,MAAME,qBAAAA,GAAwB,CAC5BC,UAAAA,EACA,EAAEC,SAAAA,GAAY,KAAK,EAAEC,yBAAyB,EAAEC,+BAA+B,EAAW,GAAA;AAE1F,IAAA,MAAMC,mBAAuF,EAAC;AAE9F,IAAA,KAAK,MAAMC,IAAAA,IAAQC,MAAAA,CAAOC,IAAI,CAACP,UAAAA,CAAAA,CAAa;QAC1C,MAAMQ,SAAAA,GAAYR,UAAU,CAACK,IAAAA,CAAK;AAElC,QAAA,OAAQG,UAAUC,IAAI;YACpB,KAAK,UAAA;AAAY,gBAAA;AACf,oBAAA,IAAI,CAACR,SAAAA,EAAW;AACd,wBAAA;AACF,oBAAA;oBAEAG,gBAAgB,CAACC,KAAK,GAAG;wBAAEI,IAAAA,EAAM,QAAA;wBAAUC,MAAAA,EAAQ,UAAA;wBAAYC,OAAAA,EAAS;AAAU,qBAAA;AAClF,oBAAA;AACF,gBAAA;YACA,KAAK,OAAA;AAAS,gBAAA;oBACZP,gBAAgB,CAACC,KAAK,GAAG;wBAAEI,IAAAA,EAAM,QAAA;wBAAUC,MAAAA,EAA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IH,gBAAAA,EAAkB;AACpB,wBAAA,MAAMI,YAAAA,GAA0C;4BAC9C3B,IAAAA,EAAM,CAAC,qBAAqB,EAAEuB,gBAAAA,CAAAA;AAChC,yBAAA;wBAEA3C,gBAAgB,CAACC,IAAAA,CAAK,GAAGoC,gBAAAA,GACrB;4BAAEhC,IAAAA,EAAM,OAAA;4BAASmB,KAAAA,EAAOuB;yBAAa,GACrCA,YAAAA;AAEJ,wBAAA;AACF,oBAAA;AAEA/C,oBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CAAcH,kBAAkB,EAAC,CAAA;AAE1D,oBAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIW,MAAM,CAAC,aAAa,EAAE5C,SAAAA,CAAUC,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF,gBAAA;AACF;AACF,IAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
|
|
@@ -16,7 +16,7 @@ import pascalCase from './pascal-case.mjs';
|
|
|
16
16
|
* @description - Converts types found on attributes to OpenAPI acceptable data types
|
|
17
17
|
*
|
|
18
18
|
* @returns Attributes using OpenAPI acceptable data types
|
|
19
|
-
*/ const cleanSchemaAttributes = (attributes, {
|
|
19
|
+
*/ const cleanSchemaAttributes = (attributes, { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas })=>{
|
|
20
20
|
const schemaAttributes = {};
|
|
21
21
|
for (const prop of Object.keys(attributes)){
|
|
22
22
|
const attribute = attributes[prop];
|
|
@@ -158,8 +158,8 @@ import pascalCase from './pascal-case.mjs';
|
|
|
158
158
|
}
|
|
159
159
|
},
|
|
160
160
|
...cleanSchemaAttributes(componentAttributes, {
|
|
161
|
-
typeMap,
|
|
162
161
|
isRequest,
|
|
162
|
+
relationTargetSchemaNames,
|
|
163
163
|
didAddStrapiComponentsToSchemas
|
|
164
164
|
})
|
|
165
165
|
}
|
|
@@ -205,8 +205,8 @@ import pascalCase from './pascal-case.mjs';
|
|
|
205
205
|
]
|
|
206
206
|
},
|
|
207
207
|
...cleanSchemaAttributes(componentAttributes, {
|
|
208
|
-
typeMap,
|
|
209
208
|
isRequest,
|
|
209
|
+
relationTargetSchemaNames,
|
|
210
210
|
didAddStrapiComponentsToSchemas
|
|
211
211
|
})
|
|
212
212
|
}
|
|
@@ -260,7 +260,7 @@ import pascalCase from './pascal-case.mjs';
|
|
|
260
260
|
break;
|
|
261
261
|
}
|
|
262
262
|
schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(imageAttributes, {
|
|
263
|
-
|
|
263
|
+
relationTargetSchemaNames,
|
|
264
264
|
didAddStrapiComponentsToSchemas
|
|
265
265
|
}));
|
|
266
266
|
break;
|
|
@@ -286,17 +286,18 @@ import pascalCase from './pascal-case.mjs';
|
|
|
286
286
|
} : oneOfType;
|
|
287
287
|
break;
|
|
288
288
|
}
|
|
289
|
-
|
|
290
|
-
|
|
289
|
+
const targetSchemaName = 'target' in attribute && attribute.target ? relationTargetSchemaNames?.get(attribute.target) : undefined;
|
|
290
|
+
if (targetSchemaName) {
|
|
291
|
+
const targetSchema = {
|
|
292
|
+
$ref: `#/components/schemas/${targetSchemaName}`
|
|
293
|
+
};
|
|
294
|
+
schemaAttributes[prop] = isListOfEntities ? {
|
|
295
|
+
type: 'array',
|
|
296
|
+
items: targetSchema
|
|
297
|
+
} : targetSchema;
|
|
291
298
|
break;
|
|
292
299
|
}
|
|
293
|
-
|
|
294
|
-
const targetAttributes = strapi.contentType(attribute.target).attributes;
|
|
295
|
-
schemaAttributes[prop] = getSchemaData(isListOfEntities, cleanSchemaAttributes(targetAttributes, {
|
|
296
|
-
typeMap,
|
|
297
|
-
isRequest,
|
|
298
|
-
didAddStrapiComponentsToSchemas
|
|
299
|
-
}));
|
|
300
|
+
schemaAttributes[prop] = getSchemaData(isListOfEntities, {});
|
|
300
301
|
break;
|
|
301
302
|
}
|
|
302
303
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean-schema-attributes.mjs","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n typeMap?: Map<string, boolean>;\n isRequest?: boolean;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { typeMap = new Map(), isRequest = false, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, { typeMap, didAddStrapiComponentsToSchemas })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n if (!('target' in attribute) || !attribute.target || typeMap.has(attribute.target)) {\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n\n typeMap.set(attribute.target, true);\n const targetAttributes = strapi.contentType(attribute.target).attributes;\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(targetAttributes, {\n typeMap,\n isRequest,\n didAddStrapiComponentsToSchemas,\n })\n );\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","typeMap","Map","isRequest","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","target","has","set","targetAttributes","Error"],"mappings":";;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAAA,GAAqB,CAAA,EAAGC,UAAAA,CAAWH,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAAA,EAAO;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAAA,CAAAA,CAAoB;AACrD,IAAA;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;AAIC,IACD,MAAME,qBAAAA,GAAwB,CAC5BC,UAAAA,EACA,EAAEC,OAAAA,GAAU,IAAIC,GAAAA,EAAK,EAAEC,SAAAA,GAAY,KAAK,EAAEC,+BAA+B,EAAW,GAAA;AAEpF,IAAA,MAAMC,mBAAuF,EAAC;AAE9F,IAAA,KAAK,MAAMC,IAAAA,IAAQC,MAAAA,CAAOC,IAAI,CAACR,UAAAA,CAAAA,CAAa;QAC1C,MAAMS,SAAAA,GAAYT,UAAU,CAACM,IAAAA,CAAK;AAElC,QAAA,OAAQG,UAAUC,IAAI;YACpB,KAAK,UAAA;AAAY,gBAAA;AACf,oBAAA,IAAI,CAACP,SAAAA,EAAW;AACd,wBAAA;AAC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,IAAAA,EAAM,OAAA;4BAASmB,KAAAA,EAAOe;yBAAU,GAClCA,SAAAA;AACJ,wBAAA;AACF,oBAAA;AAEA,oBAAA,IAAI,EAAE,QAAA,IAAYnC,SAAQ,KAAM,CAACA,SAAAA,CAAUuC,MAAM,IAAI/C,OAAAA,CAAQgD,GAAG,CAACxC,SAAAA,CAAUuC,MAAM,CAAA,EAAG;AAClF3C,wBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CAAcH,kBAAkB,EAAC,CAAA;AAE1D,wBAAA;AACF,oBAAA;AAEAzC,oBAAAA,OAAAA,CAAQiD,GAAG,CAACzC,SAAAA,CAAUuC,MAAM,EAAE,IAAA,CAAA;AAC9B,oBAAA,MAAMG,mBAAmBjC,MAAAA,CAAOuB,WAAW,CAAChC,SAAAA,CAAUuC,MAAM,EAAEhD,UAAU;AAExEK,oBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CACvBH,gBAAAA,EACA3C,sBAAsBoD,gBAAAA,EAAkB;AACtClD,wBAAAA,OAAAA;AACAE,wBAAAA,SAAAA;AACAC,wBAAAA;AACF,qBAAA,CAAA,CAAA;AAGF,oBAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIgD,MAAM,CAAC,aAAa,EAAE3C,SAAAA,CAAUC,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF,gBAAA;AACF;AACF,IAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"clean-schema-attributes.mjs","sources":["../../../../../server/src/services/helpers/utils/clean-schema-attributes.ts"],"sourcesContent":["import type { Struct } from '@strapi/types';\nimport type { OpenAPIV3 } from 'openapi-types';\n\nimport getSchemaData from './get-schema-data';\nimport pascalCase from './pascal-case';\n\ninterface Options {\n isRequest?: boolean;\n relationTargetSchemaNames?: Map<string, string>;\n didAddStrapiComponentsToSchemas: (name: string, schema: object) => boolean;\n}\n\n/**\n * @description - Convert attribute component names to OpenAPI component names\n *\n * @returns OpenAPI component name\n */\nconst convertComponentName = (component: string, isRef = false): string => {\n const cleanComponentName = `${pascalCase(component)}Component`;\n\n if (isRef) {\n return `#/components/schemas/${cleanComponentName}`;\n }\n return cleanComponentName;\n};\n\n/**\n * @description - Converts types found on attributes to OpenAPI acceptable data types\n *\n * @returns Attributes using OpenAPI acceptable data types\n */\nconst cleanSchemaAttributes = (\n attributes: Struct.SchemaAttributes,\n { isRequest = false, relationTargetSchemaNames, didAddStrapiComponentsToSchemas }: Options\n): Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> => {\n const schemaAttributes: Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject> = {};\n\n for (const prop of Object.keys(attributes)) {\n const attribute = attributes[prop];\n\n switch (attribute.type) {\n case 'password': {\n if (!isRequest) {\n break;\n }\n\n schemaAttributes[prop] = { type: 'string', format: 'password', example: '*******' };\n break;\n }\n case 'email': {\n schemaAttributes[prop] = { type: 'string', format: 'email' };\n break;\n }\n case 'string':\n case 'text':\n case 'richtext': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'timestamp': {\n schemaAttributes[prop] = { type: 'string', format: 'timestamp', example: Date.now() };\n break;\n }\n case 'time': {\n schemaAttributes[prop] = { type: 'string', format: 'time', example: '12:54.000' };\n break;\n }\n case 'date': {\n schemaAttributes[prop] = { type: 'string', format: 'date' };\n break;\n }\n case 'datetime': {\n schemaAttributes[prop] = { type: 'string', format: 'date-time' };\n break;\n }\n case 'boolean': {\n schemaAttributes[prop] = { type: 'boolean' };\n break;\n }\n case 'enumeration': {\n schemaAttributes[prop] = { type: 'string', enum: [...attribute.enum] };\n break;\n }\n case 'decimal':\n case 'float': {\n schemaAttributes[prop] = { type: 'number', format: 'float' };\n break;\n }\n case 'integer': {\n schemaAttributes[prop] = { type: 'integer' };\n break;\n }\n case 'biginteger': {\n schemaAttributes[prop] = { type: 'string', pattern: '^\\\\d*$', example: '123456789' };\n break;\n }\n case 'json':\n case 'blocks': {\n schemaAttributes[prop] = {};\n break;\n }\n case 'uid': {\n schemaAttributes[prop] = { type: 'string' };\n break;\n }\n case 'component': {\n const componentAttributes = strapi.components[attribute.component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(attribute.component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(attribute.component),\n rawComponentSchema\n );\n\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n if (attribute.repeatable) {\n schemaAttributes[prop] = {\n type: 'array',\n items: finalComponentSchema,\n };\n } else {\n schemaAttributes[prop] = finalComponentSchema;\n }\n break;\n }\n case 'dynamiczone': {\n const components = attribute.components.map((component) => {\n const componentAttributes = strapi.components[component].attributes;\n const rawComponentSchema: OpenAPIV3.SchemaObject = {\n type: 'object',\n properties: {\n ...(isRequest ? {} : { id: { oneOf: [{ type: 'string' }, { type: 'number' }] } }),\n __component: { type: 'string', enum: [component] },\n ...cleanSchemaAttributes(componentAttributes, {\n isRequest,\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n }),\n },\n };\n\n const refComponentSchema: OpenAPIV3.ReferenceObject = {\n $ref: convertComponentName(component, true),\n };\n\n const componentExists = didAddStrapiComponentsToSchemas(\n convertComponentName(component),\n rawComponentSchema\n );\n const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema;\n return finalComponentSchema;\n });\n let discriminator: OpenAPIV3.DiscriminatorObject | undefined;\n if (components.every((component) => Object.hasOwn(component, '$ref'))) {\n discriminator = {\n propertyName: '__component',\n mapping: attribute.components.reduce(\n (acc, component) => {\n acc[component] = convertComponentName(component, true);\n return acc;\n },\n {} as {\n [value: string]: string;\n }\n ),\n };\n }\n\n schemaAttributes[prop] = {\n type: 'array',\n items: {\n anyOf: components,\n },\n discriminator,\n };\n break;\n }\n case 'media': {\n const imageAttributes = strapi.contentType('plugin::upload.file').attributes;\n const isListOfEntities = attribute.multiple ?? false;\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(\n isListOfEntities,\n cleanSchemaAttributes(imageAttributes, {\n relationTargetSchemaNames,\n didAddStrapiComponentsToSchemas,\n })\n );\n break;\n }\n\n case 'relation': {\n const isListOfEntities = attribute.relation.includes('ToMany');\n\n if (isRequest) {\n const oneOfType: OpenAPIV3.SchemaObject = {\n oneOf: [{ type: 'integer' }, { type: 'string' }],\n example: 'string or id',\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: oneOfType }\n : oneOfType;\n break;\n }\n\n const targetSchemaName =\n 'target' in attribute && attribute.target\n ? relationTargetSchemaNames?.get(attribute.target)\n : undefined;\n\n if (targetSchemaName) {\n const targetSchema: OpenAPIV3.ReferenceObject = {\n $ref: `#/components/schemas/${targetSchemaName}`,\n };\n\n schemaAttributes[prop] = isListOfEntities\n ? { type: 'array', items: targetSchema }\n : targetSchema;\n\n break;\n }\n\n schemaAttributes[prop] = getSchemaData(isListOfEntities, {});\n\n break;\n }\n default: {\n // @ts-expect-error - This is a catch all for any other types\n throw new Error(`Invalid type ${attribute.type} while generating open api schema.`);\n }\n }\n }\n\n return schemaAttributes;\n};\n\nexport default cleanSchemaAttributes;\n"],"names":["convertComponentName","component","isRef","cleanComponentName","pascalCase","cleanSchemaAttributes","attributes","isRequest","relationTargetSchemaNames","didAddStrapiComponentsToSchemas","schemaAttributes","prop","Object","keys","attribute","type","format","example","Date","now","enum","pattern","componentAttributes","strapi","components","rawComponentSchema","properties","id","oneOf","refComponentSchema","$ref","componentExists","finalComponentSchema","repeatable","items","map","__component","discriminator","every","hasOwn","propertyName","mapping","reduce","acc","anyOf","imageAttributes","contentType","isListOfEntities","multiple","oneOfType","getSchemaData","relation","includes","targetSchemaName","target","get","undefined","targetSchema","Error"],"mappings":";;;AAYA;;;;AAIC,IACD,MAAMA,oBAAAA,GAAuB,CAACC,SAAAA,EAAmBC,QAAQ,KAAK,GAAA;AAC5D,IAAA,MAAMC,kBAAAA,GAAqB,CAAA,EAAGC,UAAAA,CAAWH,SAAAA,CAAAA,CAAW,SAAS,CAAC;AAE9D,IAAA,IAAIC,KAAAA,EAAO;QACT,OAAO,CAAC,qBAAqB,EAAEC,kBAAAA,CAAAA,CAAoB;AACrD,IAAA;IACA,OAAOA,kBAAAA;AACT,CAAA;AAEA;;;;IAKA,MAAME,qBAAAA,GAAwB,CAC5BC,UAAAA,EACA,EAAEC,SAAAA,GAAY,KAAK,EAAEC,yBAAyB,EAAEC,+BAA+B,EAAW,GAAA;AAE1F,IAAA,MAAMC,mBAAuF,EAAC;AAE9F,IAAA,KAAK,MAAMC,IAAAA,IAAQC,MAAAA,CAAOC,IAAI,CAACP,UAAAA,CAAAA,CAAa;QAC1C,MAAMQ,SAAAA,GAAYR,UAAU,CAACK,IAAAA,CAAK;AAElC,QAAA,OAAQG,UAAUC,IAAI;YACpB,KAAK,UAAA;AAAY,gBAAA;AACf,oBAAA,IAAI,CAACR,SAAAA,EAAW;AACd,wBAAA;AACF,oBAAA;oBAEAG,gBAAgB,CAACC,KAAK,GAAG;wBAAEI,IAAAA,EAAM,QAAA;wBAAUC,MAAAA,EAAQ,UAAA;wBAAYC,OAAAA,EAAS;AAAU,qBAAA;AAClF,oBAAA;AACF,gBAAA;YACA,KAAK,OAAA;AAAS,gBAAA;oBACZP,gBAAgB,CAACC,KAAK,GAAG;wBAAEI,IAAAA,EAAM,QAAA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AA;AAEN,oBAAA,IAAIH,gBAAAA,EAAkB;AACpB,wBAAA,MAAMI,YAAAA,GAA0C;4BAC9C3B,IAAAA,EAAM,CAAC,qBAAqB,EAAEuB,gBAAAA,CAAAA;AAChC,yBAAA;wBAEA3C,gBAAgB,CAACC,IAAAA,CAAK,GAAGoC,gBAAAA,GACrB;4BAAEhC,IAAAA,EAAM,OAAA;4BAASmB,KAAAA,EAAOuB;yBAAa,GACrCA,YAAAA;AAEJ,wBAAA;AACF,oBAAA;AAEA/C,oBAAAA,gBAAgB,CAACC,IAAAA,CAAK,GAAGuC,aAAAA,CAAcH,kBAAkB,EAAC,CAAA;AAE1D,oBAAA;AACF,gBAAA;AACA,YAAA;AAAS,gBAAA;;oBAEP,MAAM,IAAIW,MAAM,CAAC,aAAa,EAAE5C,SAAAA,CAAUC,IAAI,CAAC,kCAAkC,CAAC,CAAA;AACpF,gBAAA;AACF;AACF,IAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
|
|
@@ -26,6 +26,7 @@ var ___default = /*#__PURE__*/_interopDefault(_);
|
|
|
26
26
|
const uniqueName = api.name === contentTypeName ? apiName : `${apiName} - ${___default.default.upperFirst(contentTypeName)}`;
|
|
27
27
|
const apiInfo = {
|
|
28
28
|
...api,
|
|
29
|
+
uid,
|
|
29
30
|
routeInfo,
|
|
30
31
|
attributes,
|
|
31
32
|
uniqueName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-content-type-names.js","sources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;;;;;;;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC;AACd,IAAA,KAAK,MAAMC,eAAAA,IAAmBH,GAAAA,CAAII,OAAO,CAAE;;AAEzC,QAAA,MAAMC,GAAAA,GAAM,CAAA,EAAGL,GAAAA,CAAIM,MAAM,CAAC,EAAE,EAAEN,GAAAA,CAAIO,IAAI,CAAC,CAAC,EAAEJ,eAAAA,CAAAA,CAAiB;QAE3D,MAAM,EAAEK,UAAU,EAAEC,IAAAA,EAAMC,eAAe,EAAEC,IAAI,EAAE,GAAGC,MAAAA,CAAOC,WAAW,CAACR,GAAAA,CAAAA;;QAGvE,MAAMS,SAAAA,GACJd,IAAIM,MAAM,KAAK,WAEXM,MAAAA,CAAOG,MAAM,CAACf,GAAAA,CAAIO,IAAI,CAAA,CAAES,MAAM,CAAC,aAAA,CAAc,GAC7CJ,MAAAA,CAAOZ,GAAG,CAACA,IAAIO,IAAI,CAAA,CAAES,MAAM,CAACb,eAAAA,CAAgB;;AAGlD,QAAA,IAAI,CAACW,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;;AAGA,QAAA,MAAMG,OAAAA,GAAUC,kBAAAA,CAAEC,UAAU,CAACnB,IAAIO,IAAI,CAAA;;AAGrC,QAAA,MAAMa,UAAAA,GACJpB,GAAAA,CAAIO,IAAI,KAAKJ,eAAAA,GAAkBc,OAAAA,GAAU,CAAA,EAAGA,OAAAA,CAAQ,GAAG,EAAEC,kBAAAA,CAAEC,UAAU,CAAChB,eAAAA,CAAAA,CAAAA,CAAkB;AAE1F,QAAA,MAAMkB,OAAAA,GAAU;AACd,YAAA,GAAGrB,GAAG;
|
|
1
|
+
{"version":3,"file":"loop-content-type-names.js","sources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n uid,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;;;;;;;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC;AACd,IAAA,KAAK,MAAMC,eAAAA,IAAmBH,GAAAA,CAAII,OAAO,CAAE;;AAEzC,QAAA,MAAMC,GAAAA,GAAM,CAAA,EAAGL,GAAAA,CAAIM,MAAM,CAAC,EAAE,EAAEN,GAAAA,CAAIO,IAAI,CAAC,CAAC,EAAEJ,eAAAA,CAAAA,CAAiB;QAE3D,MAAM,EAAEK,UAAU,EAAEC,IAAAA,EAAMC,eAAe,EAAEC,IAAI,EAAE,GAAGC,MAAAA,CAAOC,WAAW,CAACR,GAAAA,CAAAA;;QAGvE,MAAMS,SAAAA,GACJd,IAAIM,MAAM,KAAK,WAEXM,MAAAA,CAAOG,MAAM,CAACf,GAAAA,CAAIO,IAAI,CAAA,CAAES,MAAM,CAAC,aAAA,CAAc,GAC7CJ,MAAAA,CAAOZ,GAAG,CAACA,IAAIO,IAAI,CAAA,CAAES,MAAM,CAACb,eAAAA,CAAgB;;AAGlD,QAAA,IAAI,CAACW,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;;AAGA,QAAA,MAAMG,OAAAA,GAAUC,kBAAAA,CAAEC,UAAU,CAACnB,IAAIO,IAAI,CAAA;;AAGrC,QAAA,MAAMa,UAAAA,GACJpB,GAAAA,CAAIO,IAAI,KAAKJ,eAAAA,GAAkBc,OAAAA,GAAU,CAAA,EAAGA,OAAAA,CAAQ,GAAG,EAAEC,kBAAAA,CAAEC,UAAU,CAAChB,eAAAA,CAAAA,CAAAA,CAAkB;AAE1F,QAAA,MAAMkB,OAAAA,GAAU;AACd,YAAA,GAAGrB,GAAG;AACNK,YAAAA,GAAAA;AACAS,YAAAA,SAAAA;AACAN,YAAAA,UAAAA;AACAY,YAAAA,UAAAA;AACAV,YAAAA,eAAAA;AACAC,YAAAA;AACF,SAAA;QAEAT,MAAAA,GAAS;AACP,YAAA,GAAGA,MAAM;AACT,YAAA,GAAGD,SAASoB,OAAAA;AACd,SAAA;AACF,IAAA;IAEA,OAAOnB,MAAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-content-type-names.mjs","sources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC;AACd,IAAA,KAAK,MAAMC,eAAAA,IAAmBH,GAAAA,CAAII,OAAO,CAAE;;AAEzC,QAAA,MAAMC,GAAAA,GAAM,CAAA,EAAGL,GAAAA,CAAIM,MAAM,CAAC,EAAE,EAAEN,GAAAA,CAAIO,IAAI,CAAC,CAAC,EAAEJ,eAAAA,CAAAA,CAAiB;QAE3D,MAAM,EAAEK,UAAU,EAAEC,IAAAA,EAAMC,eAAe,EAAEC,IAAI,EAAE,GAAGC,MAAAA,CAAOC,WAAW,CAACR,GAAAA,CAAAA;;QAGvE,MAAMS,SAAAA,GACJd,IAAIM,MAAM,KAAK,WAEXM,MAAAA,CAAOG,MAAM,CAACf,GAAAA,CAAIO,IAAI,CAAA,CAAES,MAAM,CAAC,aAAA,CAAc,GAC7CJ,MAAAA,CAAOZ,GAAG,CAACA,IAAIO,IAAI,CAAA,CAAES,MAAM,CAACb,eAAAA,CAAgB;;AAGlD,QAAA,IAAI,CAACW,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;;AAGA,QAAA,MAAMG,OAAAA,GAAUC,CAAAA,CAAEC,UAAU,CAACnB,IAAIO,IAAI,CAAA;;AAGrC,QAAA,MAAMa,UAAAA,GACJpB,GAAAA,CAAIO,IAAI,KAAKJ,eAAAA,GAAkBc,OAAAA,GAAU,CAAA,EAAGA,OAAAA,CAAQ,GAAG,EAAEC,CAAAA,CAAEC,UAAU,CAAChB,eAAAA,CAAAA,CAAAA,CAAkB;AAE1F,QAAA,MAAMkB,OAAAA,GAAU;AACd,YAAA,GAAGrB,GAAG;
|
|
1
|
+
{"version":3,"file":"loop-content-type-names.mjs","sources":["../../../../../server/src/services/helpers/utils/loop-content-type-names.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport type { Api, ApiInfo } from '../../../types';\n\n/**\n * @description A reusable loop for building api endpoint paths and component schemas\n */\nconst loopContentTypeNames = (api: Api, callback: (info: ApiInfo) => any) => {\n let result = {};\n for (const contentTypeName of api.ctNames) {\n // Get the attributes found on the api's contentType\n const uid = `${api.getter}::${api.name}.${contentTypeName}`;\n\n const { attributes, info: contentTypeInfo, kind } = strapi.contentType(uid as any);\n\n // Get the routes for the current api\n const routeInfo =\n api.getter === 'plugin'\n ? // @ts-expect-error – TODO: fix this\n strapi.plugin(api.name).routes['content-api']\n : strapi.api(api.name).routes[contentTypeName];\n\n // Continue to next iteration if routeInfo is undefined\n if (!routeInfo) {\n continue;\n }\n\n // Uppercase the first letter of the api name\n const apiName = _.upperFirst(api.name);\n\n // Create a unique name if the api name and contentType name don't match\n const uniqueName =\n api.name === contentTypeName ? apiName : `${apiName} - ${_.upperFirst(contentTypeName)}`;\n\n const apiInfo = {\n ...api,\n uid,\n routeInfo,\n attributes,\n uniqueName,\n contentTypeInfo,\n kind,\n };\n\n result = {\n ...result,\n ...callback(apiInfo),\n };\n }\n\n return result;\n};\n\nexport default loopContentTypeNames;\n"],"names":["loopContentTypeNames","api","callback","result","contentTypeName","ctNames","uid","getter","name","attributes","info","contentTypeInfo","kind","strapi","contentType","routeInfo","plugin","routes","apiName","_","upperFirst","uniqueName","apiInfo"],"mappings":";;AAIA;;IAGA,MAAMA,oBAAAA,GAAuB,CAACC,GAAAA,EAAUC,QAAAA,GAAAA;AACtC,IAAA,IAAIC,SAAS,EAAC;AACd,IAAA,KAAK,MAAMC,eAAAA,IAAmBH,GAAAA,CAAII,OAAO,CAAE;;AAEzC,QAAA,MAAMC,GAAAA,GAAM,CAAA,EAAGL,GAAAA,CAAIM,MAAM,CAAC,EAAE,EAAEN,GAAAA,CAAIO,IAAI,CAAC,CAAC,EAAEJ,eAAAA,CAAAA,CAAiB;QAE3D,MAAM,EAAEK,UAAU,EAAEC,IAAAA,EAAMC,eAAe,EAAEC,IAAI,EAAE,GAAGC,MAAAA,CAAOC,WAAW,CAACR,GAAAA,CAAAA;;QAGvE,MAAMS,SAAAA,GACJd,IAAIM,MAAM,KAAK,WAEXM,MAAAA,CAAOG,MAAM,CAACf,GAAAA,CAAIO,IAAI,CAAA,CAAES,MAAM,CAAC,aAAA,CAAc,GAC7CJ,MAAAA,CAAOZ,GAAG,CAACA,IAAIO,IAAI,CAAA,CAAES,MAAM,CAACb,eAAAA,CAAgB;;AAGlD,QAAA,IAAI,CAACW,SAAAA,EAAW;AACd,YAAA;AACF,QAAA;;AAGA,QAAA,MAAMG,OAAAA,GAAUC,CAAAA,CAAEC,UAAU,CAACnB,IAAIO,IAAI,CAAA;;AAGrC,QAAA,MAAMa,UAAAA,GACJpB,GAAAA,CAAIO,IAAI,KAAKJ,eAAAA,GAAkBc,OAAAA,GAAU,CAAA,EAAGA,OAAAA,CAAQ,GAAG,EAAEC,CAAAA,CAAEC,UAAU,CAAChB,eAAAA,CAAAA,CAAAA,CAAkB;AAE1F,QAAA,MAAMkB,OAAAA,GAAU;AACd,YAAA,GAAGrB,GAAG;AACNK,YAAAA,GAAAA;AACAS,YAAAA,SAAAA;AACAN,YAAAA,UAAAA;AACAY,YAAAA,UAAAA;AACAV,YAAAA,eAAAA;AACAC,YAAAA;AACF,SAAA;QAEAT,MAAAA,GAAS;AACP,YAAA,GAAGA,MAAM;AACT,YAAA,GAAGD,SAASoB,OAAAA;AACd,SAAA;AACF,IAAA;IAEA,OAAOnB,MAAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-params.js","sources":["../../../../../server/src/services/helpers/utils/query-params.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\nconst params: OpenAPIV3.ParameterObject[] = [\n {\n name: 'sort',\n in: 'query',\n description: 'Sort by attributes ascending (asc) or descending (desc)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'pagination[withCount]',\n in: 'query',\n description: 'Return page/pageSize (default: true)',\n deprecated: false,\n required: false,\n schema: {\n type: 'boolean',\n },\n },\n {\n name: 'pagination[page]',\n in: 'query',\n description: 'Page number (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[pageSize]',\n in: 'query',\n description: 'Page size (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[start]',\n in: 'query',\n description: 'Offset value (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[limit]',\n in: 'query',\n description: 'Number of entities to return (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'fields',\n in: 'query',\n description: 'Fields to return (ex: title,author)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'populate',\n in: 'query',\n description: 'Relations to return',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'filters',\n in: 'query',\n description: 'Filters to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'object',\n additionalProperties: true,\n },\n style: 'deepObject',\n },\n {\n name: 'locale',\n in: 'query',\n description: 'Locale to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n];\n\nexport default params;\n"],"names":["params","name","in","description","deprecated","required","schema","type","additionalProperties","style"],"mappings":";;AAEA,MAAMA,MAAAA,GAAsC;AAC1C,IAAA;QACEC,IAAAA,EAAM,MAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,yDAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,uBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,sCAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,kBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,0BAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,sBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,yBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,mBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,2BAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,mBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,4CAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,QAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,qCAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,UAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,qBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;
|
|
1
|
+
{"version":3,"file":"query-params.js","sources":["../../../../../server/src/services/helpers/utils/query-params.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\nconst params: OpenAPIV3.ParameterObject[] = [\n {\n name: 'sort',\n in: 'query',\n description: 'Sort by attributes ascending (asc) or descending (desc)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'pagination[withCount]',\n in: 'query',\n description: 'Return page/pageSize (default: true)',\n deprecated: false,\n required: false,\n schema: {\n type: 'boolean',\n },\n },\n {\n name: 'pagination[page]',\n in: 'query',\n description: 'Page number (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[pageSize]',\n in: 'query',\n description: 'Page size (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[start]',\n in: 'query',\n description: 'Offset value (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[limit]',\n in: 'query',\n description: 'Number of entities to return (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'fields',\n in: 'query',\n description: 'Fields to return (ex: title,author)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'populate',\n in: 'query',\n description: 'Relations to return',\n deprecated: false,\n required: false,\n schema: {\n oneOf: [\n { type: 'string' },\n {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n ],\n },\n },\n {\n name: 'filters',\n in: 'query',\n description: 'Filters to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'object',\n additionalProperties: true,\n },\n style: 'deepObject',\n },\n {\n name: 'locale',\n in: 'query',\n description: 'Locale to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n];\n\nexport default params;\n"],"names":["params","name","in","description","deprecated","required","schema","type","oneOf","items","additionalProperties","style"],"mappings":";;AAEA,MAAMA,MAAAA,GAAsC;AAC1C,IAAA;QACEC,IAAAA,EAAM,MAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,yDAAA;QACbC,UAAAA,EAAY,KAAA;QACZC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;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,UAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,qBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNE,KAAAA,EAAO;AACL,gBAAA;oBAAED,IAAAA,EAAM;AAAS,iBAAA;AACjB,gBAAA;oBACEA,IAAAA,EAAM,OAAA;oBACNE,KAAAA,EAAO;wBACLF,IAAAA,EAAM;AACR;AACF;AACD;AACH;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,SAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,kBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM,QAAA;YACNG,oBAAAA,EAAsB;AACxB,SAAA;QACAC,KAAAA,EAAO;AACT,KAAA;AACA,IAAA;QACEV,IAAAA,EAAM,QAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,iBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-params.mjs","sources":["../../../../../server/src/services/helpers/utils/query-params.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\nconst params: OpenAPIV3.ParameterObject[] = [\n {\n name: 'sort',\n in: 'query',\n description: 'Sort by attributes ascending (asc) or descending (desc)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'pagination[withCount]',\n in: 'query',\n description: 'Return page/pageSize (default: true)',\n deprecated: false,\n required: false,\n schema: {\n type: 'boolean',\n },\n },\n {\n name: 'pagination[page]',\n in: 'query',\n description: 'Page number (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[pageSize]',\n in: 'query',\n description: 'Page size (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[start]',\n in: 'query',\n description: 'Offset value (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[limit]',\n in: 'query',\n description: 'Number of entities to return (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'fields',\n in: 'query',\n description: 'Fields to return (ex: title,author)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'populate',\n in: 'query',\n description: 'Relations to return',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'filters',\n in: 'query',\n description: 'Filters to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'object',\n additionalProperties: true,\n },\n style: 'deepObject',\n },\n {\n name: 'locale',\n in: 'query',\n description: 'Locale to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n];\n\nexport default params;\n"],"names":["params","name","in","description","deprecated","required","schema","type","additionalProperties","style"],"mappings":"AAEA,MAAMA,MAAAA,GAAsC;AAC1C,IAAA;QACEC,IAAAA,EAAM,MAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,yDAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,uBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,sCAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,kBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,0BAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,sBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,yBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,mBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,2BAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,mBAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,4CAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,QAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,qCAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,UAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,qBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;
|
|
1
|
+
{"version":3,"file":"query-params.mjs","sources":["../../../../../server/src/services/helpers/utils/query-params.ts"],"sourcesContent":["import type { OpenAPIV3 } from 'openapi-types';\n\nconst params: OpenAPIV3.ParameterObject[] = [\n {\n name: 'sort',\n in: 'query',\n description: 'Sort by attributes ascending (asc) or descending (desc)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'pagination[withCount]',\n in: 'query',\n description: 'Return page/pageSize (default: true)',\n deprecated: false,\n required: false,\n schema: {\n type: 'boolean',\n },\n },\n {\n name: 'pagination[page]',\n in: 'query',\n description: 'Page number (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[pageSize]',\n in: 'query',\n description: 'Page size (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[start]',\n in: 'query',\n description: 'Offset value (default: 0)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'pagination[limit]',\n in: 'query',\n description: 'Number of entities to return (default: 25)',\n deprecated: false,\n required: false,\n schema: {\n type: 'integer',\n },\n },\n {\n name: 'fields',\n in: 'query',\n description: 'Fields to return (ex: title,author)',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n {\n name: 'populate',\n in: 'query',\n description: 'Relations to return',\n deprecated: false,\n required: false,\n schema: {\n oneOf: [\n { type: 'string' },\n {\n type: 'array',\n items: {\n type: 'string',\n },\n },\n ],\n },\n },\n {\n name: 'filters',\n in: 'query',\n description: 'Filters to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'object',\n additionalProperties: true,\n },\n style: 'deepObject',\n },\n {\n name: 'locale',\n in: 'query',\n description: 'Locale to apply',\n deprecated: false,\n required: false,\n schema: {\n type: 'string',\n },\n },\n];\n\nexport default params;\n"],"names":["params","name","in","description","deprecated","required","schema","type","oneOf","items","additionalProperties","style"],"mappings":"AAEA,MAAMA,MAAAA,GAAsC;AAC1C,IAAA;QACEC,IAAAA,EAAM,MAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,yDAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AAC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AAI,OAAA;QACJC,WAAAA,EAAa,qBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNE,KAAAA,EAAO;AACL,gBAAA;oBAAED,IAAAA,EAAM;AAAS,iBAAA;AACjB,gBAAA;oBACEA,IAAAA,EAAM,OAAA;oBACNE,KAAAA,EAAO;wBACLF,IAAAA,EAAM;AACR;AACF;AACD;AACH;AACF,KAAA;AACA,IAAA;QACEN,IAAAA,EAAM,SAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,kBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM,QAAA;YACNG,oBAAAA,EAAsB;AACxB,SAAA;QACAC,KAAAA,EAAO;AACT,KAAA;AACA,IAAA;QACEV,IAAAA,EAAM,QAAA;QACNC,EAAAA,EAAI,OAAA;QACJC,WAAAA,EAAa,iBAAA;QACbC,UAAAA,EAAY,KAAA;QACZC,QAAAA,EAAU,KAAA;QACVC,MAAAA,EAAQ;YACNC,IAAAA,EAAM;AACR;AACF;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../server/src/services/index.ts"],"sourcesContent":["// import type { Common } from '@strapi/types';\n\nimport documentation, { type DocumentationService } from './documentation';\nimport override, { type OverrideService } from './override';\n\nexport default {\n documentation,\n override,\n}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type {} from '../types';\n\n// import type { Common } from '@strapi/types';\n\nimport documentation, { type DocumentationService } from './documentation';\nimport override, { type OverrideService } from './override';\n\n/** Names of the registered Documentation services. */\ntype RegisteredNames = keyof Core.RegisteredFor<\n Strapi.Registries.PackageServices,\n 'plugin::documentation'\n>;\n\nexport default {\n documentation,\n override,\n} satisfies Record<RegisteredNames, unknown>;\n\nexport type Services = {\n documentation: DocumentationService;\n override: OverrideService;\n};\n"],"names":["documentation","override"],"mappings":";;;;;AAGA;AAWA,eAAe;AACbA,IAAAA,aAAAA;AACAC,IAAAA;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../server/src/services/index.ts"],"sourcesContent":["// import type { Common } from '@strapi/types';\n\nimport documentation, { type DocumentationService } from './documentation';\nimport override, { type OverrideService } from './override';\n\nexport default {\n documentation,\n override,\n}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../server/src/services/index.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type {} from '../types';\n\n// import type { Common } from '@strapi/types';\n\nimport documentation, { type DocumentationService } from './documentation';\nimport override, { type OverrideService } from './override';\n\n/** Names of the registered Documentation services. */\ntype RegisteredNames = keyof Core.RegisteredFor<\n Strapi.Registries.PackageServices,\n 'plugin::documentation'\n>;\n\nexport default {\n documentation,\n override,\n} satisfies Record<RegisteredNames, unknown>;\n\nexport type Services = {\n documentation: DocumentationService;\n override: OverrideService;\n};\n"],"names":["documentation","override"],"mappings":";;;AAGA;AAWA,eAAe;AACbA,mBAAAA,eAAAA;AACAC,cAAAA;AACF,CAAA;;;;"}
|