【发布时间】:2017-10-10 18:50:51
【问题描述】:
我正在为我的 api 构建一个 hapi-swagger 接口。其中一个查询参数 type 有另一个查询参数 subtype 依赖于前者。我已经想出了如何实现Joivalidation for it successfully,但在接口方面并不那么成功。我的验证码是
{
type: Joi.string()
.valid('image', 'publication', 'dataset')
.optional(),
subtype: Joi.string()
.optional()
.when('type', {is: 'image', then: Joi.valid('png', 'jpg')})
.when('type', {is: 'publication', then: Joi.valid('newspaper', 'book')})
.description('subtype based on the file_type')
}
但界面只显示 subtype 的 png 和 jpg。关于如何实现这一点的建议,以便在选择相应的 type 时显示正确的 subtype?
【问题讨论】:
标签: swagger hapijs hapi-swagger