MCPcopy Create free account
hub / github.com/apitable/apitable / validateMagicForm

Function validateMagicForm

packages/core/src/automation_manager/validate.ts:50–161  ·  view source on GitHub ↗
(rootSchema: JSONSchema7, formData: any)

Source from the content-addressed store, hash-verified

48};
49
50export const validateMagicForm = (rootSchema: JSONSchema7, formData: any) => {
51 let validationError: any = null;
52 const propertyErrors: any[] = [];
53 try {
54 if (rootSchema.type === 'object') {
55 // console.log(Object.keys(rootSchema.properties!));
56 if (typeof formData !== 'object') {
57 propertyErrors.push({
58 instancePath: '',
59 schemaPath: '#/type',
60 keyword: 'type',
61 params: { type: 'object' },
62 message: 'must be object'
63 });
64 } else {
65 Object.keys(rootSchema.properties!).forEach(propertyKey => {
66 const propertySchema = rootSchema.properties![propertyKey] as JSONSchema7;
67 const isRequired = rootSchema.required && rootSchema.required.indexOf(propertyKey) !== -1;
68 const propertyValue = getObjectOperandProperty(formData, propertyKey, propertySchema);
69 // console.log('validateFormData', {
70 // propertyKey, propertySchema, propertyValue, isRequired,
71 // rootSchema, formData,
72 // });
73 if (isRequired) {
74 if (isOperandNullValue(propertyValue, propertySchema)) {
75 propertyErrors.push({
76 dataPath: `.${propertyKey}`,
77 keyword: 'required',
78 message: t(Strings.robot_config_empty_warning),
79 params: { missingProperty: propertyKey },
80 schemaPath: '#/required',
81 });
82 } else {
83 if (propertySchema.enum) {
84 if (isLiteralOperand(propertyValue) && !propertySchema.enum!.includes(getLiteralOperandValue(propertyValue))) {
85 propertyErrors.push({
86 dataPath: `.${propertyKey}`,
87 keyword: 'enum',
88 message: t(Strings.robot_config_empty_warning),
89 params: { enum: propertySchema.enum },
90 schemaPath: '#/enum',
91 });
92 }
93 }
94 }
95 } else {
96 if (propertySchema.enum) {
97 if (isLiteralOperand(propertyValue) && !propertySchema.enum!.includes(getLiteralOperandValue(propertyValue))) {
98 propertyErrors.push({
99 dataPath: `.${propertyKey}`,
100 keyword: 'enum',
101 message: 'The specified option does not exist', // TODO: i18n
102 params: { enum: propertySchema.enum },
103 schemaPath: '#/enum',
104 });
105 }
106 }
107 if (isOperandNullValue(propertyValue, propertySchema)) {

Callers 4

validate.test.tsFile · 0.90
activeRobotMethod · 0.90
validateFormDataFunction · 0.90

Calls 9

getObjectOperandPropertyFunction · 0.90
isOperandNullValueFunction · 0.90
tFunction · 0.90
isLiteralOperandFunction · 0.90
getLiteralOperandValueFunction · 0.90
getOperandValueTypeFunction · 0.90
keysMethod · 0.65
pushMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected