Team Ai
Apppublic

oex2003/evolution-api

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
label.schema.ts39 linesDownload Raw Back to validate
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