From 59793db5b41b382f498f4bbc0ae05bda84eb2df3 Mon Sep 17 00:00:00 2001 From: Andrei Wilkens Date: Fri, 3 Jun 2022 14:57:30 +0200 Subject: [PATCH 1/6] fix #13453 Documentation Plugin doesn't generate Proper Type for the Localization prop , and doesn't generate Refs for Components in Dynamic Zones --- .../helpers/build-component-schema.js | 60 +++++++++++----- .../helpers/utils/clean-schema-attributes.js | 71 +++++++++++++------ 2 files changed, 93 insertions(+), 38 deletions(-) diff --git a/packages/plugins/documentation/server/services/helpers/build-component-schema.js b/packages/plugins/documentation/server/services/helpers/build-component-schema.js index e245bddeb7..db7770e8e2 100644 --- a/packages/plugins/documentation/server/services/helpers/build-component-schema.js +++ b/packages/plugins/documentation/server/services/helpers/build-component-schema.js @@ -19,6 +19,17 @@ const { hasFindMethod, isLocalizedPath } = require('./utils/routes'); const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { // Store response and request schemas in an object let schemas = {}; + let componentSchemas = {}; + const addSchema = (schemaName, schema) => { + if(!Object.keys(schema) || !Object.keys(schema?.properties)) { + return false; + } + componentSchemas = { + ...componentSchemas, + [schemaName]: schema + } + return true; + } // Get all the route methods const routeMethods = routeInfo.routes.map(route => route.method); // Check for localized paths @@ -53,7 +64,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { [`${pascalCase(uniqueName)}LocalizationRequest`]: { required: [...requiredAttributes, 'locale'], type: 'object', - properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true }), + properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true, addSchema }), }, }; } @@ -68,7 +79,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { data: { required: requiredAttributes, type: 'object', - properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true }), + properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true, addSchema }), }, }, }, @@ -82,7 +93,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { type: 'object', properties: { id: { type: 'string' }, - ...cleanSchemaAttributes(attributes), + ...cleanSchemaAttributes(attributes, { addSchema }), }, }, }; @@ -94,17 +105,26 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { // Build the list response schema schemas = { ...schemas, + [`${pascalCase(uniqueName)}ListResponseDataItem`]:{ + type: 'object', + properties: { + id: { type: 'string' }, + attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema, dataTypeName: `#/components/schemas/${pascalCase(uniqueName)}ListResponseDataItemLocalized`}) }, + }, + }, + [`${pascalCase(uniqueName)}ListResponseDataItemLocalized`]: { + type: 'object', + properties: { + id: { type: 'string' }, + attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema }) }, + }, + }, [`${pascalCase(uniqueName)}ListResponse`]: { - type: 'object', properties: { data: { type: 'array', items: { - type: 'object', - properties: { - id: { type: 'string' }, - attributes: { type: 'object', properties: cleanSchemaAttributes(attributes) }, - }, + "$ref": `#/components/schemas/${pascalCase(uniqueName)}ListResponseDataItem` }, }, meta: { @@ -128,22 +148,30 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { // Build the response schema schemas = { ...schemas, - [`${pascalCase(uniqueName)}Response`]: { - type: 'object', - properties: { - data: { + [`${pascalCase(uniqueName)}ResponseDataObject`]: { type: 'object', properties: { id: { type: 'string' }, - attributes: { type: 'object', properties: cleanSchemaAttributes(attributes) }, + attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema, dataTypeName: `#/components/schemas/${pascalCase(uniqueName)}ResponseDataObjectLocalized` }) }, }, }, + [`${pascalCase(uniqueName)}ResponseDataObjectLocalized`]: { + type: 'object', + properties: { + id: { type: 'string' }, + attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema }) }, + }, + }, + [`${pascalCase(uniqueName)}Response`]: { + properties: { + data: { + "$ref": `#/components/schemas/${pascalCase(uniqueName)}ResponseDataObject` + }, meta: { type: 'object' }, }, }, }; - - return schemas; + return {...schemas, ...componentSchemas}; }; const buildComponentSchema = api => { diff --git a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js index 0c8bc4a467..a0e6387c38 100644 --- a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js +++ b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const getSchemaData = require('./get-schema-data'); - +const pascalCase = require('./pascal-case'); /** * @description - Converts types found on attributes to OpenAPI acceptable data types * @@ -10,7 +10,7 @@ const getSchemaData = require('./get-schema-data'); * @param {{ typeMap: Map, isRequest: boolean }} opts * @returns Attributes using OpenAPI acceptable data types */ -const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = false } = {}) => { +const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = false, addSchema = () => {}, dataTypeName = "" } = {}, ) => { const attributesCopy = _.cloneDeep(attributes); for (const prop in attributesCopy) { @@ -86,20 +86,7 @@ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = fa } case 'component': { const componentAttributes = strapi.components[attribute.component].attributes; - - if (attribute.repeatable) { - attributesCopy[prop] = { - type: 'array', - items: { - type: 'object', - properties: { - ...(isRequest ? {} : { id: { type: 'string' } }), - ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest }), - }, - }, - }; - } else { - attributesCopy[prop] = { + const componentExists = addSchema(pascalCase(attribute.component),{ type: 'object', properties: { ...(isRequest ? {} : { id: { type: 'string' } }), @@ -108,21 +95,58 @@ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = fa isRequest, }), }, - }; + }) + if (attribute.repeatable) { + attributesCopy[prop] = { + type: 'array', + items: componentExists ? + {"$ref": `#/components/schemas/${pascalCase(attribute.component)}`} + : { + type: 'object', + properties: { + ...(isRequest ? {} : { id: { type: 'string' } }), + ...cleanSchemaAttributes(componentAttributes, { + typeMap, + isRequest, + }), + }, + } + }; + } else { + attributesCopy[prop] = componentExists ? + {"$ref": `#/components/schemas/${pascalCase(attribute.component)}`} + : { + type: 'object', + properties: { + ...(isRequest ? {} : { id: { type: 'string' } }), + ...cleanSchemaAttributes(componentAttributes, { + typeMap, + isRequest, + }), + }, + }; } break; } case 'dynamiczone': { const components = attribute.components.map(component => { const componentAttributes = strapi.components[component].attributes; - return { + const componentExists = addSchema(pascalCase(component),{ type: 'object', properties: { ...(isRequest ? {} : { id: { type: 'string' } }), __component: { type: 'string' }, - ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest }), + ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest, addSchema }), }, - }; + }) + return componentExists ? {"$ref": `#/components/schemas/${pascalCase(component)}`} : { + type: 'object', + properties: { + ...(isRequest ? {} : { id: { type: 'string' } }), + __component: { type: 'string' }, + ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest, addSchema }), + }, + } }); attributesCopy[prop] = { @@ -171,8 +195,11 @@ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = fa if (prop === 'localizations') { attributesCopy[prop] = { - type: 'array', - items: { type: 'object', properties: {} }, + type: 'object', + properties: { data: { + type: 'array', + items: dataTypeName.length ? { '$ref' : dataTypeName } : {} + } }, }; break; } From 6d168f8c5489f98a8d079b7e09d22d70e8d74b83 Mon Sep 17 00:00:00 2001 From: Andrei Wilkens Date: Fri, 3 Jun 2022 16:33:25 +0200 Subject: [PATCH 2/6] remove ? --- .../server/services/helpers/build-component-schema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugins/documentation/server/services/helpers/build-component-schema.js b/packages/plugins/documentation/server/services/helpers/build-component-schema.js index db7770e8e2..7bcf5d620e 100644 --- a/packages/plugins/documentation/server/services/helpers/build-component-schema.js +++ b/packages/plugins/documentation/server/services/helpers/build-component-schema.js @@ -21,7 +21,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { let schemas = {}; let componentSchemas = {}; const addSchema = (schemaName, schema) => { - if(!Object.keys(schema) || !Object.keys(schema?.properties)) { + if(!Object.keys(schema) || !Object.keys(schema.properties)) { return false; } componentSchemas = { From 9b57d63af4f8715253cf2d55e6c24197e5356bdd Mon Sep 17 00:00:00 2001 From: Andrei Wilkens Date: Thu, 30 Jun 2022 13:01:19 +0200 Subject: [PATCH 3/6] Adjusted Review changes --- .../helpers/build-component-schema.js | 72 +++++++++------ .../helpers/utils/clean-schema-attributes.js | 87 ++++++++----------- 2 files changed, 84 insertions(+), 75 deletions(-) diff --git a/packages/plugins/documentation/server/services/helpers/build-component-schema.js b/packages/plugins/documentation/server/services/helpers/build-component-schema.js index 7bcf5d620e..99149a8229 100644 --- a/packages/plugins/documentation/server/services/helpers/build-component-schema.js +++ b/packages/plugins/documentation/server/services/helpers/build-component-schema.js @@ -21,15 +21,15 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { let schemas = {}; let componentSchemas = {}; const addSchema = (schemaName, schema) => { - if(!Object.keys(schema) || !Object.keys(schema.properties)) { + if (!Object.keys(schema) || !Object.keys(schema.properties)) { return false; } componentSchemas = { ...componentSchemas, - [schemaName]: schema - } + [schemaName]: schema, + }; return true; - } + }; // Get all the route methods const routeMethods = routeInfo.routes.map(route => route.method); // Check for localized paths @@ -105,26 +105,37 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { // Build the list response schema schemas = { ...schemas, - [`${pascalCase(uniqueName)}ListResponseDataItem`]:{ - type: 'object', - properties: { - id: { type: 'string' }, - attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema, dataTypeName: `#/components/schemas/${pascalCase(uniqueName)}ListResponseDataItemLocalized`}) }, + [`${pascalCase(uniqueName)}ListResponseDataItem`]: { + type: 'object', + properties: { + id: { type: 'string' }, + attributes: { + type: 'object', + properties: cleanSchemaAttributes(attributes, { + addSchema, + componentSchemaRefName: `#/components/schemas/${pascalCase( + uniqueName + )}ListResponseDataItemLocalized`, + }), }, }, - [`${pascalCase(uniqueName)}ListResponseDataItemLocalized`]: { + }, + [`${pascalCase(uniqueName)}ListResponseDataItemLocalized`]: { + type: 'object', + properties: { + id: { type: 'string' }, + attributes: { type: 'object', - properties: { - id: { type: 'string' }, - attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema }) }, - }, + properties: cleanSchemaAttributes(attributes, { addSchema }), + }, }, + }, [`${pascalCase(uniqueName)}ListResponse`]: { properties: { data: { type: 'array', items: { - "$ref": `#/components/schemas/${pascalCase(uniqueName)}ListResponseDataItem` + $ref: `#/components/schemas/${pascalCase(uniqueName)}ListResponseDataItem`, }, }, meta: { @@ -149,29 +160,40 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { schemas = { ...schemas, [`${pascalCase(uniqueName)}ResponseDataObject`]: { + type: 'object', + properties: { + id: { type: 'string' }, + attributes: { type: 'object', - properties: { - id: { type: 'string' }, - attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema, dataTypeName: `#/components/schemas/${pascalCase(uniqueName)}ResponseDataObjectLocalized` }) }, - }, + properties: cleanSchemaAttributes(attributes, { + addSchema, + componentSchemaRefName: `#/components/schemas/${pascalCase( + uniqueName + )}ResponseDataObjectLocalized`, + }), }, + }, + }, [`${pascalCase(uniqueName)}ResponseDataObjectLocalized`]: { + type: 'object', + properties: { + id: { type: 'string' }, + attributes: { type: 'object', - properties: { - id: { type: 'string' }, - attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { addSchema }) }, - }, + properties: cleanSchemaAttributes(attributes, { addSchema }), }, + }, + }, [`${pascalCase(uniqueName)}Response`]: { properties: { data: { - "$ref": `#/components/schemas/${pascalCase(uniqueName)}ResponseDataObject` + $ref: `#/components/schemas/${pascalCase(uniqueName)}ResponseDataObject`, }, meta: { type: 'object' }, }, }, }; - return {...schemas, ...componentSchemas}; + return { ...schemas, ...componentSchemas }; }; const buildComponentSchema = api => { diff --git a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js index a0e6387c38..9237bbd636 100644 --- a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js +++ b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js @@ -10,7 +10,10 @@ const pascalCase = require('./pascal-case'); * @param {{ typeMap: Map, isRequest: boolean }} opts * @returns Attributes using OpenAPI acceptable data types */ -const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = false, addSchema = () => {}, dataTypeName = "" } = {}, ) => { +const cleanSchemaAttributes = ( + attributes, + { typeMap = new Map(), isRequest = false, addSchema = () => {}, componentSchemaRefName = '' } = {} +) => { const attributesCopy = _.cloneDeep(attributes); for (const prop in attributesCopy) { @@ -86,67 +89,49 @@ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = fa } case 'component': { const componentAttributes = strapi.components[attribute.component].attributes; - const componentExists = addSchema(pascalCase(attribute.component),{ - type: 'object', - properties: { - ...(isRequest ? {} : { id: { type: 'string' } }), - ...cleanSchemaAttributes(componentAttributes, { - typeMap, - isRequest, - }), - }, - }) + const rawComponentSchema = { + type: 'object', + properties: { + ...(isRequest ? {} : { id: { type: 'string' } }), + ...cleanSchemaAttributes(componentAttributes, { + typeMap, + isRequest, + }), + }, + }; + const refComponentSchema = { + $ref: `#/components/schemas/${`${pascalCase(attribute.component)}Component`}`, + }; + const componentExists = addSchema( + `${pascalCase(attribute.component)}Component`, + rawComponentSchema + ); + const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema; if (attribute.repeatable) { attributesCopy[prop] = { type: 'array', - items: componentExists ? - {"$ref": `#/components/schemas/${pascalCase(attribute.component)}`} - : { - type: 'object', - properties: { - ...(isRequest ? {} : { id: { type: 'string' } }), - ...cleanSchemaAttributes(componentAttributes, { - typeMap, - isRequest, - }), - }, - } - }; + items: finalComponentSchema, + }; } else { - attributesCopy[prop] = componentExists ? - {"$ref": `#/components/schemas/${pascalCase(attribute.component)}`} - : { - type: 'object', - properties: { - ...(isRequest ? {} : { id: { type: 'string' } }), - ...cleanSchemaAttributes(componentAttributes, { - typeMap, - isRequest, - }), - }, - }; + attributesCopy[prop] = finalComponentSchema; } break; } case 'dynamiczone': { const components = attribute.components.map(component => { const componentAttributes = strapi.components[component].attributes; - const componentExists = addSchema(pascalCase(component),{ + const rawComponentSchema = { type: 'object', properties: { ...(isRequest ? {} : { id: { type: 'string' } }), __component: { type: 'string' }, ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest, addSchema }), }, - }) - return componentExists ? {"$ref": `#/components/schemas/${pascalCase(component)}`} : { - type: 'object', - properties: { - ...(isRequest ? {} : { id: { type: 'string' } }), - __component: { type: 'string' }, - ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest, addSchema }), - }, - } + }; + const refComponentSchema = { $ref: `#/components/schemas/${pascalCase(component)}` }; + const componentExists = addSchema(pascalCase(component), rawComponentSchema); + const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema; + return finalComponentSchema; }); attributesCopy[prop] = { @@ -196,10 +181,12 @@ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = fa if (prop === 'localizations') { attributesCopy[prop] = { type: 'object', - properties: { data: { - type: 'array', - items: dataTypeName.length ? { '$ref' : dataTypeName } : {} - } }, + properties: { + data: { + type: 'array', + items: componentSchemaRefName.length ? { $ref: componentSchemaRefName } : {}, + }, + }, }; break; } From 82d2921964850c9e1ea038108ca13fecce47346b Mon Sep 17 00:00:00 2001 From: Andrei Wilkens Date: Thu, 30 Jun 2022 13:03:52 +0200 Subject: [PATCH 4/6] added jsdoc for new params --- .../server/services/helpers/utils/clean-schema-attributes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js index 9237bbd636..3fca73bdd3 100644 --- a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js +++ b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js @@ -7,7 +7,7 @@ const pascalCase = require('./pascal-case'); * @description - Converts types found on attributes to OpenAPI acceptable data types * * @param {object} attributes - The attributes found on a contentType - * @param {{ typeMap: Map, isRequest: boolean }} opts + * @param {{ typeMap: Map, isRequest: boolean, addSchema: function, componentSchemaRefName: string }} opts * @returns Attributes using OpenAPI acceptable data types */ const cleanSchemaAttributes = ( From be96961ff966fe1fd77ff152de071f71fd5f00b9 Mon Sep 17 00:00:00 2001 From: Andrei Wilkens Date: Thu, 30 Jun 2022 13:09:24 +0200 Subject: [PATCH 5/6] comment --- .../server/services/helpers/build-component-schema.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/plugins/documentation/server/services/helpers/build-component-schema.js b/packages/plugins/documentation/server/services/helpers/build-component-schema.js index 99149a8229..0d79b0100e 100644 --- a/packages/plugins/documentation/server/services/helpers/build-component-schema.js +++ b/packages/plugins/documentation/server/services/helpers/build-component-schema.js @@ -20,6 +20,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { // Store response and request schemas in an object let schemas = {}; let componentSchemas = {}; + // adds a ComponentSchema to the Schemas so it can be used as Ref const addSchema = (schemaName, schema) => { if (!Object.keys(schema) || !Object.keys(schema.properties)) { return false; From f4519a89a12a9b396d11b2110883b84ada41e324 Mon Sep 17 00:00:00 2001 From: Andrei Wilkens Date: Mon, 1 Aug 2022 13:44:21 +0200 Subject: [PATCH 6/6] renamed addSchema to addComponentSchema and fixed a template string --- .../services/helpers/build-component-schema.js | 16 ++++++++-------- .../helpers/utils/clean-schema-attributes.js | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/plugins/documentation/server/services/helpers/build-component-schema.js b/packages/plugins/documentation/server/services/helpers/build-component-schema.js index 0d79b0100e..7f504e75b8 100644 --- a/packages/plugins/documentation/server/services/helpers/build-component-schema.js +++ b/packages/plugins/documentation/server/services/helpers/build-component-schema.js @@ -21,7 +21,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { let schemas = {}; let componentSchemas = {}; // adds a ComponentSchema to the Schemas so it can be used as Ref - const addSchema = (schemaName, schema) => { + const addComponentSchema = (schemaName, schema) => { if (!Object.keys(schema) || !Object.keys(schema.properties)) { return false; } @@ -65,7 +65,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { [`${pascalCase(uniqueName)}LocalizationRequest`]: { required: [...requiredAttributes, 'locale'], type: 'object', - properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true, addSchema }), + properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true, addComponentSchema }), }, }; } @@ -80,7 +80,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { data: { required: requiredAttributes, type: 'object', - properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true, addSchema }), + properties: cleanSchemaAttributes(attributesForRequest, { isRequest: true, addComponentSchema }), }, }, }, @@ -94,7 +94,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { type: 'object', properties: { id: { type: 'string' }, - ...cleanSchemaAttributes(attributes, { addSchema }), + ...cleanSchemaAttributes(attributes, { addComponentSchema }), }, }, }; @@ -113,7 +113,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { - addSchema, + addComponentSchema, componentSchemaRefName: `#/components/schemas/${pascalCase( uniqueName )}ListResponseDataItemLocalized`, @@ -127,7 +127,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { id: { type: 'string' }, attributes: { type: 'object', - properties: cleanSchemaAttributes(attributes, { addSchema }), + properties: cleanSchemaAttributes(attributes, { addComponentSchema }), }, }, }, @@ -167,7 +167,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { attributes: { type: 'object', properties: cleanSchemaAttributes(attributes, { - addSchema, + addComponentSchema, componentSchemaRefName: `#/components/schemas/${pascalCase( uniqueName )}ResponseDataObjectLocalized`, @@ -181,7 +181,7 @@ const getAllSchemasForContentType = ({ routeInfo, attributes, uniqueName }) => { id: { type: 'string' }, attributes: { type: 'object', - properties: cleanSchemaAttributes(attributes, { addSchema }), + properties: cleanSchemaAttributes(attributes, { addComponentSchema }), }, }, }, diff --git a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js index 3fca73bdd3..0b8b31826b 100644 --- a/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js +++ b/packages/plugins/documentation/server/services/helpers/utils/clean-schema-attributes.js @@ -7,12 +7,12 @@ const pascalCase = require('./pascal-case'); * @description - Converts types found on attributes to OpenAPI acceptable data types * * @param {object} attributes - The attributes found on a contentType - * @param {{ typeMap: Map, isRequest: boolean, addSchema: function, componentSchemaRefName: string }} opts + * @param {{ typeMap: Map, isRequest: boolean, addComponentSchema: function, componentSchemaRefName: string }} opts * @returns Attributes using OpenAPI acceptable data types */ const cleanSchemaAttributes = ( attributes, - { typeMap = new Map(), isRequest = false, addSchema = () => {}, componentSchemaRefName = '' } = {} + { typeMap = new Map(), isRequest = false, addComponentSchema = () => {}, componentSchemaRefName = '' } = {} ) => { const attributesCopy = _.cloneDeep(attributes); @@ -100,9 +100,9 @@ const cleanSchemaAttributes = ( }, }; const refComponentSchema = { - $ref: `#/components/schemas/${`${pascalCase(attribute.component)}Component`}`, + $ref: `#/components/schemas/${pascalCase(attribute.component)}Component`, }; - const componentExists = addSchema( + const componentExists = addComponentSchema( `${pascalCase(attribute.component)}Component`, rawComponentSchema ); @@ -125,11 +125,11 @@ const cleanSchemaAttributes = ( properties: { ...(isRequest ? {} : { id: { type: 'string' } }), __component: { type: 'string' }, - ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest, addSchema }), + ...cleanSchemaAttributes(componentAttributes, { typeMap, isRequest, addComponentSchema }), }, }; const refComponentSchema = { $ref: `#/components/schemas/${pascalCase(component)}` }; - const componentExists = addSchema(pascalCase(component), rawComponentSchema); + const componentExists = addComponentSchema(pascalCase(component), rawComponentSchema); const finalComponentSchema = componentExists ? refComponentSchema : rawComponentSchema; return finalComponentSchema; });