oex2003/evolution-api
0
1import { JSONSchema7, JSONSchema7Definition } from 'json-schema';2import { v4 } from 'uuid';3 4const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {5 const properties = {};6 propertyNames.forEach(7 (property) =>8 (properties[property] = {9 minLength: 1,10 description: `The "${property}" cannot be empty`,11 }),12 );13 return {14 if: {15 propertyNames: {16 enum: [...propertyNames],17 },18 },19 then: { properties },20 };21};22 23const numberDefinition: JSONSchema7Definition = {24 type: 'string',25 description: 'Invalid format',26};27 28export const handleLabelSchema: JSONSchema7 = {29 $id: v4(),30 type: 'object',31 properties: {32 number: { ...numberDefinition },33 labelId: { type: 'string' },34 action: { type: 'string', enum: ['add', 'remove'] },35 },36 required: ['number', 'labelId', 'action'],37 ...isNotEmpty('number', 'labelId', 'action'),38};39 