0

我需要验证以下内容: Json data: { tag: 'picture', picture: 'some string'}

Json模式:{标签:{'type':'string'},??????? // 第二个key应该是'tag'的数据值

编辑:我希望用 ajv 模式验证器来完成这个

谢谢!!

4

1 回答 1

0

您可以使用 $data 参考(需要 $data 选项):

{
  "type": "object",
  "properties": {
    "tag": {"type": "string"}
  },
  "additionalProperties": {}, // any schema for the second property value
  "propertyNames": {
    "anyOf": [
      {"const": "tag"},
      {"const": {"$data": "1/tag"} }
    ]
  }
}

$data 是对 JSON 模式下一个版本的提议。

https://runkit.com/esp/59e0d803bf8366001374c2a2

于 2017-10-13T15:19:12.823 回答