joiful-ts / joiful

TypeScript Declarative Validation for Joi
239 stars 18 forks source link

Unknown/Pattern object #161

Closed lal12 closed 4 years ago

lal12 commented 4 years ago

I have an object where I need one property to be a generic key/value object. So in TS:

class MyEntitiy{
   options: {[key: string]: OptionType};
}

Usually with joi I would do joi.object().unknown(true) or joi.object().pattern(/.*/, joi.object()). Is there a way for this in joiful?

I also could imagine other cases where more generic joi functions are useful e.g.

class MyEntity{
   property: string|SomeObjectType;
}

So something generic like @joiful.schema(mySchema) would be useful. For this specific example it would be something like @joiful.schema(joiful.joi.alternatives(joi.string(),joi.object())).

lal12 commented 4 years ago

Ok, my vscode intelli sense was a bit laggy. I have found @joiful.any().custom() by now.

PeteBa commented 3 years ago

@lal12 , sorry to resurrect this partial thread, but I'm struggling with exactly the two examples you have in the message above. i.e. how to validate the config below. I have tried various things with @jf.any().custom() but cant quite make it work. Did you manage to find a solution ?

class MyEntitiy{
   options: {[key: string]: OptionType};
}

and

class MyEntity{
   property: string|SomeObjectType;
}