xogroup / felicity

Javascript object constructors and sample data based on Joi schema.
Other
111 stars 9 forks source link

Joi.object().pattern() is not supported. And it should be. #100

Closed WesTyler closed 7 years ago

WesTyler commented 7 years ago

Context

What are you trying to achieve or the steps to reproduce ?

Using the Joi schema Joi.object().pattern() should be supported in both .entityFor and .example methods.

const schema = Joi.object().pattern(/^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$/, Joi.object().keys({
    id  : Joi.string().guid().required(),
    tags: Joi.array().items(Joi.string()).required()
})).min(2);

const example = Felicity.example(schema);

What result did you expect ?

example
/*
{
    '4dffdb09-9e60-423d-b956-a9b821fb8fde': {
        id: '4dffdb09-9e60-423d-b956-a9b821fb8fde',
        tags: []
    },
    '3ad38506-3ef4-4e93-a745-023f8e8ccf75': {
        id: '3ad38506-3ef4-4e93-a745-023f8e8ccf75',
        tags: []
    }
}
*/

What result did you observe ?

Only the .min(2) is respected. Example fails validation.

example
/*
{
    wdgx: 'wdgx6obscdnbrtz9kldavpldi',
    ppfz: 'ppfzbv353bdllftgdzllq5mi'
}
*/
WesTyler commented 7 years ago

Currently hacking on this between diaper changes