You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenAPI 2.0中如何实现anyOf替代方案?适用于Power Automate自定义连接器

在OpenAPI 2.0中实现Power Automate自定义连接器的可选连接参数组

由于OpenAPI 2.0不支持anyOf/oneOf关键字,你可以通过以下两种方案实现可选参数组的需求:

方案1:通过依赖规则强制参数组互斥

无需额外区分字段,直接通过Schema约束确保用户只能填写其中一组参数:

"connectionParameters": {
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "param1": {
      "type": "string",
      "title": "参数1"
    },
    "param2": {
      "type": "string",
      "title": "参数2"
    },
    "alternateparam1": {
      "type": "string",
      "title": "备选参数1"
    },
    "alternateparam2": {
      "type": "string",
      "title": "备选参数2"
    }
  },
  // 强制恰好填写2个参数(对应一组参数的数量)
  "minProperties": 2,
  "maxProperties": 2,
  "dependencies": {
    // 填写param1时,必须同时填param2,且不能填备选参数
    "param1": {
      "required": ["param2"],
      "properties": {
        "alternateparam1": { "not": {} },
        "alternateparam2": { "not": {} }
      }
    },
    // 填写param2时,必须同时填param1,且不能填备选参数
    "param2": {
      "required": ["param1"],
      "properties": {
        "alternateparam1": { "not": {} },
        "alternateparam2": { "not": {} }
      }
    },
    // 填写备选参数1时,必须同时填备选参数2,且不能填默认参数
    "alternateparam1": {
      "required": ["alternateparam2"],
      "properties": {
        "param1": { "not": {} },
        "param2": { "not": {} }
      }
    },
    // 填写备选参数2时,必须同时填备选参数1,且不能填默认参数
    "alternateparam2": {
      "required": ["alternateparam1"],
      "properties": {
        "param1": { "not": {} },
        "param2": { "not": {} }
      }
    }
  }
}

核心规则说明:

  • additionalProperties: false:禁止填写Schema未定义的参数
  • minProperties/maxProperties:确保用户只能填写完整的一组参数
  • dependencies:定义参数间的依赖关系,同时通过not关键字排除另一组参数的填写

方案2:添加区分字段实现动态参数组推荐

新增一个选择字段(如authType),让用户明确选择参数组,Power Automate UI会根据选择动态显示对应参数,体验更友好:

"connectionParameters": {
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "authType": {
      "type": "string",
      "title": "认证方式",
      "enum": ["default", "alternate"],
      "description": "选择要使用的参数组"
    },
    "param1": {
      "type": "string",
      "title": "参数1"
    },
    "param2": {
      "type": "string",
      "title": "参数2"
    },
    "alternateparam1": {
      "type": "string",
      "title": "备选参数1"
    },
    "alternateparam2": {
      "type": "string",
      "title": "备选参数2"
    }
  },
  "required": ["authType"],
  "dependencies": {
    "authType": {
      "oneOf": [
        {
          "properties": {
            "authType": { "enum": ["default"] }
          },
          "required": ["param1", "param2"]
        },
        {
          "properties": {
            "authType": { "enum": ["alternate"] }
          },
          "required": ["alternateparam1", "alternateparam2"]
        }
      ]
    }
  }
}

核心规则说明:

  • authType作为区分字段,用户选择后触发对应参数组的必填规则
  • oneOf关联选择值与参数组(注:尽管OpenAPI 2.0官方未明确支持,但Power Automate自定义连接器通常兼容JSON Schema Draft 4的该关键字)
  • UI层面会根据authType的选择自动显示/隐藏对应参数组,降低用户操作复杂度

内容的提问来源于stack exchange,提问作者Vrishank Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 21:55:25