【问题标题】:ajv does not return when validating a valid json验证有效 json 时 ajv 不返回
【发布时间】: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"
    }
}

然后根本没有回应。

我尝试整合架构,但没有任何区别。我希望我犯了一些简单的初学者错误,有人可能会发现!我花了很多时间试图找出问题所在,但经过所有调试后,我没有进一步前进。

【问题讨论】:

    标签: json schema ajv


    【解决方案1】:

    我以某种方式得到了这个工作,但不知道为什么它开始工作。

    在我的测试脚本中,我添加了一行来从 elasticsearch 中删除测试索引。之后,所有的测试都通过了。然后我从我的测试脚本中删除了新行,看看它是否会再次停止工作,但它没有。

    我猜这个问题与 elasticsearch 有关...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-25
      • 2016-08-23
      • 2019-05-30
      • 1970-01-01
      • 2017-04-29
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多