从 json-schema 引用远程枚举值

Reference remote enum values from json-schema

在我的模式定义中,我有一个类型,它有一个整数 属性,它应该是“固定”数字集中的任何一个。问题是这个“固定集”可能经常变。

   "person": {
      "type": "object",
      "properties": {
        "aproperty": {
          "type": "integer",
          "enum": [1, 12, 30 ... , 1000]
        },
      }
    },

有没有办法从远程服务(将有最新的集合)引用这个数组?

   "person": {
      "type": "object",
      "properties": {
        "aproperty": {
          "type": "integer",
          "$ref": "http://localhost:8080/fixed_set"
        },
      }
    },

我尝试了 $ref,但没有成功。 如果“ref”是解决方案的一部分,那么后端应该做什么 return?

{
  "enum": [1, 12, 30 ... , 1000]
}

  "enum": [1, 12, 30 ... , 1000]

  [1, 12, 30 ... , 1000]

主架构:

    {
      "$schema": "https://json-schema.org/draft/2019-09/schema",
      "type": "object",
      "properties": {
        "aproperty": {
          "type": "integer",
          "$ref": "http://localhost:8080/fixed_set"
        },
      }
    }

子架构:

{
  "$id": "http://localhost:8080/fixed_set",
  "enum": [1, 12, 30 ... , 1000]
}

请注意,您必须使用支持 draft2019-09 的评估器才能将 $ref 识别为同级关键字。否则,您需要将其包装在 allOf:

    {
      "type": "object",
      "properties": {
        "aproperty": {
          "type": "integer",
          "allOf": [
            { "$ref": "http://localhost:8080/fixed_set" }
          ]
        },
      }
    }