Joi.alternatives([])。match('all')

时间:2019-12-06 15:23:13

标签: javascript joi

起点:

我正在尝试将一些openapi 3.0 json解析为有效的Joi模型。我在转换allOf模式方面遇到问题。

上下文:

  1. Joi似乎有一种方法可以通过Joi.alternatives([schema1,schema1]).match('all') See commit
  2. 回顾测试,对于在以下情况下有效的有效负载仍然感到困惑:

Joi测试代码: See repo

...
        it('matches all', () => {


            const schema = Joi.alternatives([
                Joi.number(),
                Joi.string()
            ])
                .match('all');


            Helper.validate(schema, [
                ['2', true, '2'],
                ['x', false, {
                    message: '"value" does not match all of the required types',
                    path: [],
                    type: 'alternatives.all',
                    context: { label: 'value', value: 'x' }
                }],
                [2, false, {
                    message: '"value" does not match all of the required types',
                    path: [],
                    type: 'alternatives.all',
                    context: { label: 'value', value: 2 }
                }],
                [true, false, {
                    message: '"value" does not match any of the allowed types',
                    path: [],
                    type: 'alternatives.any',
                    context: { label: 'value', value: true }
                }]
            ]);
        });
...

问题:

  1. 在我看来,代码可以验证'2'2。正确吗?
  2. 什么样的JOI模式可以是stringnumber

0 个答案:

没有答案