Enums 在json模式中,如何定义包含枚举中每个元素描述的枚举?

Enums 在json模式中,如何定义包含枚举中每个元素描述的枚举?,enums,jsonschema,Enums,Jsonschema,在json模式中,我可以简单地使用“enum”和可用的代码列表定义代码列表,例如: { "type": "object", "properties": { "group": { "type":"string", "$ref": "#/definitions/Group" } },

在json模式中,我可以简单地使用“enum”和可用的代码列表定义代码列表,例如:

{
  "type": "object",
  "properties": {
    "group": {
      "type":"string",  
      "$ref": "#/definitions/Group"
    }
  },

  "definitions": {
    "Group": {
      "enum": ["A","B"]
    }
  }
}
以下有效载荷将是有效的:

{
  "group": "B"
}
但是,我尝试在模式中向用户提供描述,其中“A”=“A组”,“B”=“B组”。比如:

{
  "type": "object",
  "properties": {
    "group": {
      "type":"string",  
      "$ref": "#/definitions/Group"
    }
  },

  "definitions": {
    "Group": {
      "enum": [
        {"code":"A",
         "description": "Group A"
        },
        {"code":"B",
         "description": "Group B"
        }
      ]
    }
  }
}
但我不想更改有效负载的结构(不需要“description”字段) 该说明更多地用于用户可以参考的文档目的。 这里有没有可以使用的好方法


谢谢

您可以将
anyOf
const
一起使用,而不是
enum
。然后您可以使用
标题
说明
进行文档编制

{
  "anyOf": [
    {
      "const": "A",
      "title": "Group A"
    },
    {
      "const": "B",
      "title": "Group B"
    }
  ]
}