Closed czy88840616 closed 2 months ago
我是升级upload组件,开启allowFieldsDuplication配置就行了么?现在版本是3.16.5
已发布3.16.6
当uplaod组件配置对象中allowFieldsDuplication参数设置为true时,在post请求中,原来参数校验正常的DTO会开始报错,表现为从DTO的第一个字段开始,即便请求字段类型是正确的,但是校验也不会通过。
示例: 在路由/addTag中通过AddTagDTO来校验请求参数
@Post('/addTag')
async addTag(@Files() files, @Fields() fields: AddTagDTO) {
return await this.tagService.addTag(fields, files);
}
当DTO是: 实际请求为: 返回参数验证错误:
\"level\" must be a number"
当DTO更改为: 实际请求为: 返回参数验证错误:
\"name\" must be a string"
以上问题在allowFieldsDuplication参数设置为false或不设置allowFieldsDuplication参数时,参数校验正常,能得到校验完成后的fields对象,但请求中数组类参数被覆盖的问题仍然存在。
post请求的类型还是form-data
你是要单个的时候非数组,多个才变数组?
其实只要能正确收到数组参数。在form-data请求,数组类型的参数是通过多个同名参数不同赋值来传递的,问题在于现在收到的参数就被覆盖掉了,只会有1个,其实只要不被覆盖,像在query参数中querystring 能正确解析出数组参数,无论是1个参数,还是多个同名但不同值的参数,Validate组件是能解析成数组参数的,这个不影响,问题的关键在于form-data请求中,多个同名但不同值的参数前面的会被覆盖,收到就只有1个了,所以Validate校验过后也只有1个
\3.6.16现在就已经支持数组了,只是你开启了配置,单个的值也变成了数组。#3981 现在会在单个 field 的时候调整回去。
3.6.17 处理成同名 field 多余 1 个才变成数组。
Checklist
npm test
passesAffected core subsystem(s)
Description of change
fix: #3970