【发布时间】:2017-08-15 03:49:36
【问题描述】:
我的登录端点可以有“社交”登录和“用户”登录,因此正文可能如下所示:
user: {
email: 'test@gmail.com',
password: 'test'
}
或者像这样:
authentication: {
provider: 'facebook',
token: 'abcd'
}
我想创建一个 JSON 模式来验证第一个主体或第二个主体。我偶然发现了oneOf,这就是我尝试过的:
body: {
oneOf: [{
properties: {
user: {
type: 'object',
required: [
'email',
'password'
],
email: {
type: 'string',
format: 'email'
},
password: {
type: 'string',
minLength: 6,
maxLength: 32
}
},
}
}, {
properties: {
authentication: {
type: 'object',
required: [
'provider',
'token'
],
provider: {
type: 'string',
enum: ['facebook']
},
token: {
type: 'string'
}
}
}
}]
}
但是,这给了我以下错误:
{
"keyword": "oneOf",
"dataPath": ".body",
"schemaPath": "#/properties/body/oneOf",
"params": {},
"message": "should match exactly one schema in oneOf"
}
如果有人可以帮助我为此进行 JSON 模式设置,那就太棒了。谢谢
【问题讨论】:
-
您的架构甚至不是有效的 JSON。请修复。
标签: json validation jsonschema