import { array, boolean, number, object, string } from "zod"; interface ValidationInterface { required: string[]; properties: Object; title: string; type: string; } interface HeadersAndValidationsInterface { headers: Object; validation: ValidationInterface; language: string; properties: Object; } class HeadersAndValidations { headers: Object; validation: ValidationInterface; language: string; properties: Object; validated: any = {}; constructor({ headers, validation, language, }: HeadersAndValidationsInterface) { this.headers = headers; this.validation = validation; this.language = language; this.properties = this.validation?.properties; this.parseProcesser(); } parseProcesser() { const requiredKeys = Array.from(this.validation?.required); Object.entries(this.properties).map(([key, value]) => { const isRequired: Boolean = requiredKeys.includes(key); const multipleTypes: Object[] = value?.anyOf; if (!isRequired) { multipleTypes.map((row: any) => { if (row.type !== "null") { this.validated[key] = { required: false, fieldType: this.parseType(row.type), }; } }); } else { this.validated[key] = { required: true, fieldType: this.parseType(value), }; } }); } parseType({ type }: any) { switch (type) { case "string": return string; case "number": return number; case "boolean": return boolean; case "array": return array; case "object": return object; default: return string; } } } export { HeadersAndValidations };