我正在尝试对 url 使用数组值。所以我把它作为 Joi 验证。
entity: Joi.array().allow(['person','location','organization']).unique().single().default(['person'])
如果我这样做,效果很好
http://something.com/query?entity=person&person=organization
它被entity
视为一个数组,所以当我从request
console.log(request.query.entity) // ['person', 'organization']
但是,如果我这样做
http://something.com/query?entity=person
我得到entity
字符串而不是['person']
console.log(request.query.entity) // 'person'
我想要的是我希望这个网址http://something.com/query?entity=person
被entity
视为['person']