parameter icon indicating copy to clipboard operation
parameter copied to clipboard

当给值赋值 undefined 时,required: false 校验失败

Open clChenLiang opened this issue 2 years ago • 0 comments

传参 { a: undefined } 在校验 { a: { type: 'string', required: false } } 时, 会失败。

it.only('test paramsValidates', async () => {
  const res = ctx.paramsValidate({
    a: 'string',
    b: { type: 'string', required: false },
  }, {
    a: 'ab',
    b: undefined,
  });
});

在 parameter 中,是用的 hasOwnProperty 判断是否有值: image 这里会让 b = undefined 逃逸掉。不知道是不是什么考虑设计的

clChenLiang avatar May 21 '22 13:05 clChenLiang