【发布时间】:2019-07-24 07:55:25
【问题描述】:
我有以下架构:
{
"$schema": "http://json-schema.org/schema#",
"$id": "http://api.hobnob.social/schemas/users/create.json",
"title": "Create User Schema",
"description": "For validating client-provided create user object",
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email"
},
"password": { "type": "string" },
"profile": { "$ref": "profile.json#" }
},
"required": ["email", "password"],
"additionalProperties": false
}
{
"$schema": "http://json-schema.org/schema#",
"$id": "http://api.hobnob.social/schemas/users/profile.json",
"title": "User Profile Schema",
"description": "For validating client-provided user profile object when creating and/or updating an user",
"type": "object",
"properties": {
"bio": { "type": "string" },
"summary": { "type": "string" },
"name": {
"type": "object",
"properties": {
"first": { "type": "string" },
"last": { "type": "string" },
"middle": { "type": "string" }
},
"additionalProperties": false
}
},
"additionalProperties": false
}
我正在使用 ajv 来验证它。在几乎所有情况下,我都得到了预期的结果。但是在验证包含 bio 或 summary 字段(字符串类型)的 json 时,根本没有来自 ajv 的响应。
例如我尝试验证
{
"email": "e@ma.il",
"password": "password",
"profile": {
"name": {
"first": "firstname"
},
"bio":"this is a bio"
}
}
然后根本没有回应。
我尝试整合架构,但没有任何区别。我希望我犯了一些简单的初学者错误,有人可能会发现!我花了很多时间试图找出问题所在,但经过所有调试后,我没有进一步前进。
【问题讨论】: