138
139
validate(content: unknown): { content: vObjType<T>; error: undefined } | { content: undefined; error: ValidationError } {
140
>
if (typeof content !== 'object' || content === null) {
validation.ts
141
return { content: undefined, error: { message: 'Expected object' } };
142
}
144
>
// eslint-disable-next-line local/code-no-dangerous-type-assertions
145
>
const result: vObjType<T> = {} as vObjType<T>;
146
>
147
>
for (const key in this.properties) {
148
>
const prop = this.properties[key];
149
>
// eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
150
>
const fieldValue = (content as any)[key];
151
>
152
>
const isOptional = prop instanceof Optional;
153
>
const validator: IValidator<unknown> = isOptional ? prop.validator : prop;
154
>
155
>
if (isOptional && fieldValue === undefined) {
156
// Optional field not provided, skip validation
157
continue;
158
}
160
>
const { content: value, error } = validator.validate(fieldValue);
161
>
if (error) {
162
return { content: undefined, error: { message: `Error in property '${key}': ${error.message}` } };
163
}
165
>
// eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
166
>
(result as any)[key] = value;
167
>
}
168
169
return { content: result, error: undefined };
171
172
getJSONSchema(): IJSONSchema {