joiful-ts / joiful

TypeScript Declarative Validation for Joi
239 stars 18 forks source link

Unable to validate nested data #196

Closed victorbadila closed 3 years ago

victorbadila commented 3 years ago

I'm having problems properly validating classes with nested properties, I narrowed the problem to this test:

import { object, string, validateAsClass } from 'joiful';

it("should not throw", () => {
    class A {
      @object().keys({ c: string().required() }).strict()
      b: { c: string; };
    }

    const obj = new A();
    obj.b = { c: "hey" };
    const { error } = validateAsClass(obj, A)
    assert.isNull(error);
});

Instead of the error being empty it is [ValidationError: "b.c" failed custom validation because ] and it cuts of abruptly there, no stack trace, no other relevant info in the error object. Am I missing something?

victorbadila commented 3 years ago

Nevermind, I skipped this part in the docs:

"To validate an object subproperty that has its own joiful validation:"