From f4519a89a12a9b396d11b2110883b84ada41e324 Mon Sep 17 00:00:00 2001 From: Andrei Wilkens Date: Mon, 1 Aug 2022 13:44:21 +0200 Subject: [PATCH] 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; });