ajv 在验证有效 json 时不 return
ajv does not return when validating a valid json
我有以下架构:
{
"$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 对其进行验证。在几乎所有情况下,我都能得到预期的结果。但是当验证包含生物或摘要字段(字符串类型)的 json 时,ajv 根本没有响应。
例如我尝试验证
{
"email": "e@ma.il",
"password": "password",
"profile": {
"name": {
"first": "firstname"
},
"bio":"this is a bio"
}
}
完全没有任何反应。
我尝试合并架构,但没有任何区别。我希望我犯了一些简单的初学者错误,有人可能会发现!我花了很多时间试图找出问题所在,但在我调试之后我没有进一步前进。
我以某种方式让它工作,但不确定它为什么开始工作。
在我的测试脚本中,我添加了一行以从 elasticsearch 中删除测试索引。之后,所有测试都通过了。然后我从我的测试脚本中删除了新行以查看它是否会再次停止工作,但它没有。
我猜这个问题在某种程度上与 elasticsearch 有关...
我有以下架构:
{
"$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 对其进行验证。在几乎所有情况下,我都能得到预期的结果。但是当验证包含生物或摘要字段(字符串类型)的 json 时,ajv 根本没有响应。
例如我尝试验证
{
"email": "e@ma.il",
"password": "password",
"profile": {
"name": {
"first": "firstname"
},
"bio":"this is a bio"
}
}
完全没有任何反应。
我尝试合并架构,但没有任何区别。我希望我犯了一些简单的初学者错误,有人可能会发现!我花了很多时间试图找出问题所在,但在我调试之后我没有进一步前进。
我以某种方式让它工作,但不确定它为什么开始工作。
在我的测试脚本中,我添加了一行以从 elasticsearch 中删除测试索引。之后,所有测试都通过了。然后我从我的测试脚本中删除了新行以查看它是否会再次停止工作,但它没有。
我猜这个问题在某种程度上与 elasticsearch 有关...