简体   繁体   English

使用 joi.object 进行 Joi 验证

[英]Joi validation using joi.object

trying to learn Typescript and using Joi with Hapi to write some API code and query validation.尝试学习 Typescript 并使用 Joi 和 Hapi 编写一些 API 代码和查询验证。 Ran into an issue where this works:遇到了这样的问题:

query: joi.object({
            apiKey: joi.string().required()
        })

but this does not:但这不会:

query: {
            apiKey: joi.string().required()
        }

Does anyone know what is happening here?有谁知道这里发生了什么? I get a runtime error in the second case.在第二种情况下,我收到运行时错误。

Joi 16 onwards you have to wrap your schema in Joi.object . Joi 16开始,您必须将架构包装在Joi.object This is the reason why it is not working in the second case.这就是它在第二种情况下不起作用的原因。 If you want to use the second way, you need to use Joi 15如果要使用第二种方式,则需要使用Joi 15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM