mirror of
https://github.com/strapi/strapi.git
synced 2025-09-06 15:22:59 +00:00
Add custom fields to TS generators
This commit is contained in:
parent
baad89e678
commit
cb10c9a81a
@ -29,6 +29,9 @@ export type NonUniqueAttribute = { unique: false };
|
||||
export type ConfigurableAttribute = { configurable: true };
|
||||
export type NonConfigurableAttribute = { configurable: false };
|
||||
|
||||
// custom field
|
||||
export type CustomField<T extends string, P extends object = undefined> = { customField: T, options?: P };
|
||||
|
||||
// min/max
|
||||
export type SetMinMax<T extends MinMaxOption<U>, U = number> = T;
|
||||
|
||||
|
@ -438,6 +438,8 @@ describe('Attributes', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// TODO custom field
|
||||
|
||||
describe('Plugin Options', () => {
|
||||
test('No plugin options', () => {
|
||||
const attribute = {};
|
||||
|
@ -70,6 +70,22 @@ const getAttributeModifiers = (attribute) => {
|
||||
);
|
||||
}
|
||||
|
||||
// Custom field
|
||||
if (attribute.customField) {
|
||||
addImport('CustomField');
|
||||
|
||||
const customFieldUid = factory.createStringLiteral(attribute.customField);
|
||||
const typeParams = [customFieldUid];
|
||||
|
||||
if (attribute.options) {
|
||||
typeParams.push(toTypeLiteral(attribute.options));
|
||||
}
|
||||
|
||||
modifiers.push(
|
||||
factory.createTypeReferenceNode(factory.createIdentifier('CustomField'), typeParams)
|
||||
);
|
||||
}
|
||||
|
||||
// Plugin Options
|
||||
if (!_.isEmpty(attribute.pluginOptions)) {
|
||||
addImport('SetPluginOptions');
|
||||
|
Loading…
x
Reference in New Issue
Block a user