问题描述
在使用 krakenjs/hapi-openapi 时,我似乎无法将字符串设为可选。
这里是 swagger/openApi
paths:
/string:
post:
parameters:
- name: stringBody
in: body
schema:
$ref: "#/deFinitions/StringBody"
required: true
responses:
200:
description: All good
deFinitions:
StringBody:
type: object
properties:
stringBody:
type: string
maxLength: 13
当我卷曲
curl localhost:8083/v2/string -H "Content-Type: application/json" -d '{"stringBody":""}'
我明白
{"statusCode":400,"error":"Bad Request","message":"Invalid request payload input"}
如果我通过 curl 传递一个字符,它就会很好地击中处理程序
我知道如果我在代码中定义路由,我可以添加 .allow('') 并且 Joi 会通过验证 ie
server.route({
method: 'POST',path: '/hello',handler: function (request,reply) {
return 'hello ' + ((request.payload || {}).name || 'world');
},options: {
validate: {
payload: Joi.object({
name: Joi.string().allow('')
})
},}
});
我使用以下版本
"@hapi/hapi": "^20.0.3","hapi-openapi": "^2.0.2"
干杯
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)