mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +00:00
renamed addSchema to addComponentSchema and fixed a template string
This commit is contained in:
parent
be96961ff9
commit
f4519a89a1
@ -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 }),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -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;
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user