如何制作 JSON Schema draft-4 中所需的对象键?

How do you make an object key required in JSON Schema draft-4?

我正在尝试为 :

定义 json 架构
{
   "user_id" :{
             "default" : ["a","b","c"]
             "unknown_key1" : ["xyz","def","ekj"]
             "unknown_key2" : []
             }
}

"default" 键应该始终出现在 user_id 映射中。 其余的密钥是未知的,可以是任何数字。 您能否为此定义 JSON 架构?

我已经定义了模式:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "$id$",
  "description": "-1",
  "definitions": {
    "user_id": {
      "type": "object",
      "minProperties": 1,
      "patternProperties": {
        "^[A-Za-z0-9]+": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]+$"
        }
      },
      "additionalProperties": false
    }
  },
  "type": "object",
  "minProperties": 1,
  "additionalProperties": false,
  "properties": {
    "user_id": {
      "$ref": "#/definitions/user_id"
    }
  },
  "anyOf": [
    {
      "required": [
        "v"
      ]
    }
  ]
}

不确定如何强制包括默认字段。

您在 user_id 子架构中使用了 required 关键字。

...
"definitions": {
    "user_id": {
      "type": "object",
      "minProperties": 1,
      "required": ["default"],
      "patternProperties": {
        "^[A-Za-z0-9]+": {
          "type": "string",
          "pattern": "^[A-Za-z0-9]+$"
        }
      },
      "additionalProperties": false
    }
  }
...