Add configurable as a valid api option

This commit is contained in:
Alexandre Bodin 2019-12-09 14:53:30 +01:00
parent 2fa574b061
commit fc36055ff6
4 changed files with 13 additions and 2 deletions

View File

@ -31,6 +31,7 @@ const createSchema = (types, relations, { modelType } = {}) =>
.string()
.oneOf(types)
.required(),
configurable: yup.boolean().nullable(),
...getTypeShape(attribute, { modelType }),
};

View File

@ -21,6 +21,7 @@ module.exports = (obj, validNatures) => {
.oneOf(validNatures)
.required(),
unique: validators.unique.nullable(),
configurable: yup.boolean().nullable(),
dominant: yup.boolean().nullable(),
columnName: yup.string().nullable(),
targetAttribute: REVERSE_RELATIONS.includes(obj.nature)

View File

@ -86,6 +86,8 @@ function createSchemaBuilder({ components, contentTypes }) {
return Object.keys(attributes).reduce((acc, key) => {
const attribute = attributes[key];
const { configurable } = attribute;
if (_.has(attribute, 'type')) {
if (attribute.type === 'media') {
const fileModel = strapi.getModel('file', 'upload');
@ -97,9 +99,13 @@ function createSchemaBuilder({ components, contentTypes }) {
via,
plugin: 'upload',
required: attribute.required ? true : false,
configurable: configurable === false ? false : undefined,
};
} else {
acc[key] = attribute;
acc[key] = {
...attribute,
configurable: configurable === false ? false : undefined,
};
}
return acc;
@ -118,6 +124,7 @@ function createSchemaBuilder({ components, contentTypes }) {
const attr = {
unique: unique === true ? true : undefined,
columnName: columnName || undefined,
configurable: configurable === false ? false : undefined,
};
if (!this.contentTypes.has(target)) {

View File

@ -60,7 +60,7 @@ const formatAttribute = (key, attribute, { model }) => {
const relation = (model.associations || []).find(
assoc => assoc.alias === key
);
const { plugin } = attribute;
const { plugin, configurable } = attribute;
let targetEntity = attribute.model || attribute.collection;
if (plugin === 'upload' && targetEntity === 'file') {
@ -68,6 +68,7 @@ const formatAttribute = (key, attribute, { model }) => {
type: 'media',
multiple: attribute.collection ? true : false,
required: attribute.required ? true : false,
configurable: configurable === false ? false : undefined,
};
} else {
return {
@ -77,6 +78,7 @@ const formatAttribute = (key, attribute, { model }) => {
dominant: attribute.dominant ? true : false,
targetAttribute: attribute.via || undefined,
columnName: attribute.columnName || undefined,
configurable: configurable === false ? false : undefined,
targetColumnName: _.get(
strapi.getModel(targetEntity, plugin),
['attributes', attribute.via, 'columnName'],