JSON 架构 - 验证对象属性的总和

JSON schema - validate sum of object properties

我有以下 PUT 网络请求正文架构:

{
  title: "Character",
  description: "PUT character request body parameters",
  type: "object",
  properties: {
    _id: {
      description:
        "ObjectID string for updating an existing character. Should not be present when a new character is created.",
      type: "string"
    },
    name: {
      description: "User input character name.",
      type: "string"
    },
    description: {
      description: "User input character description.",
      type: "string"
    },
    weaponId: {
      description: "ObjectID string for the equiped character weapon",
      type: "string"
    },
    armorId: {
      description: "ObjectID string for the equiped character weapon",
      type: "string"
    },
    shieldId: {
      description: "ObjectID string for the equiped character weapon",
      type: "string"
    },
    stats: {
      description: "Base character stats input by user",
      type: "object",
      properties: {
        str: {
          description: "Character strength stat.",
          type: "number",
          minimum: 100,
          maximum: 500
        },
        stam: {
          description: "Character stamina stat.",
          type: "number",
          minimum: 100,
          maximum: 500
        },
        wp: {
          description: "Character willpower stat.",
          type: "number",
          minimum: 100,
          maximum: 500
        },
        dex: {
          description: "Character dexterity stat.",
          type: "number",
          minimum: 100,
          maximum: 500
        },
        spd: {
          description: "Character speed stat.",
          type: "number",
          minimum: 100,
          maximum: 500
        }
      }
    }
  },
  required: ["name", "description", "stats"]
}

我想验证统计对象上的键的总和不超过 1000。JSON 模式是否可能 - 我在文档中没有找到任何提及。

谢谢

不,JSON 架构不可能做到这一点。

您将需要编写自己的业务逻辑代码来执行此类计算。