0

我想知道 jsonschema 是否可以验证特定字段的值,该字段仅限于在另一个字段中输入的值。例如:

{
 "type": "object",
 "properties": {
  "someStrings": {
   "type": "array",
   "title": "some strings",
   "items": {
    "type": "string"
   }
  },
  "chooseOneOfSomeStrings": {
   "type": "string",
   "limitedTo": "someStrings" // or whatever the verbiage to implement this
  }
 }
}

因此

如果我为“someStrings”输入“red”、“blue”、“green”,“chooseOneOfSomeStrings”如果是“red”则有效,如果是“yellow”则无效。

4

1 回答 1

1

您要查找的关键字是“枚举”。但是这个允许值列表需要在模式本身中——它不能在您正在验证的数据中。

...
  "chooseOneOfSomeStrings": {
   "type": "string",
   "enum": [ "red", "blue", "green" ]
  }
于 2021-07-05T22:59:10.020 回答