【问题标题】:What is the confirm password approach on json schema draft 07?json schema draft 07 上的确认密码方法是什么?
【发布时间】:2019-07-02 20:01:41
【问题描述】:

AFAIK $data 键已在 JSON 模式的草案 07 中删除,所以我想知道如何处理确认密码

我正在使用Newtonsoft JSON Schema Validator,并且我有以下架构,但我得到了下一个错误:

错误:

错误信息

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "definitions": {
    "SignIn": {
      "properties": {
        "Password": {
          "$id": "SignInPassword",
          "maxLength": 15,
          "minLength": 6,
          "type": "string"
        },
        "Username": {
          "oneOf": [
            {
              "format": "email",
              "type": "string"
            },
            {
              "pattern": "^\\+?[1-9]\\d{1,14}$",
              "type": "string"
            }
          ]
        }
      },
      "required": [
        "Password",
        "Username"
      ],
      "type": "object"
    }
  },
  "allOf": [
    {
      "$ref": "#/definitions/SignIn"
    },
    {
      "properties": {
        "ConfirmPassword": {
          "const": {
            "$data": "1/Password"          
          },
          "minLength": 6,
          "type": "string"
        }
      },
      "required": [
        "ConfirmPassword"
      ],
      "type": "object"
    }
  ]
}

【问题讨论】:

    标签: jsonschema


    【解决方案1】:

    $data 从来不是 JSON Schema 的一部分。

    使用纯 JSON Schema,您无法实现您的要求。

    有人提议添加$data,一些库实现了它,但从未包含在实际规范中。

    【讨论】:

    • 好的,记住这一点...我的方法是确保两个键具有相同的约束...但在 ConfirmPassword 上添加说明,说明其值必须与密码相同。 . 听起来对吗?
    • 您可以通过引用相同的定义来确保它们具有相同的约束,但您无法使用 JSON Schema 验证它们是否是相同的值。作为业务逻辑验证的一部分,您必须这样做。
    猜你喜欢
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 2011-06-29
    • 2015-06-18
    • 2015-06-01
    • 2017-06-24
    • 1970-01-01
    • 2021-05-21
    相关资源
    最近更新 更多