如何为 Azure Logic Apps 的触发器 JSON 架构中的字段设置默认值?
How to set default value for a field in Azure Logic Apps' trigger JSON Schema?
我正在使用触发器设置 Azure 逻辑应用程序工作流,但目前无法在 JSON 架构中为此类触发器的字段定义默认值。
我已启用 JSON 架构验证和必填字段,如下所述:https://www.danrigby.com/2018/08/27/enable-schema-validation-and-required-fields-in-logicapps/
我的 JSON 架构目前如下所示:
{
"anyOf": [
{
"required": [
"delay"
]
},
{
"required": [
"startTime"
]
}
],
"properties": {
"callbackUrl": {
"type": "string"
},
"delay": {
"default": 0,
"minimum": 0,
"type": "integer"
},
"startTime": {
"type": "string"
}
},
"required": [
"callbackUrl"
],
"type": "object"
}
我也试过用 defaultValue
替换 default
但没有成功。
我希望 delay
在不存在时填充为 0,但它在 Azure 逻辑应用程序工作流中被解释为 null
,导致以下布尔条件失败,例如 delay is greater than 0
因为他们不希望评估空值。
我相信 JSON 架构仅用于此处的验证,因为它在许多情况下都是如此。 default
属性 被许多实现忽略,如 official docs.
中提到的
相反,您可以在 null
上需要默认值的地方使用此表达式
if (equals(triggerBody()?['delay'], null), triggerBody()?['delay'], 0)
我正在使用触发器设置 Azure 逻辑应用程序工作流,但目前无法在 JSON 架构中为此类触发器的字段定义默认值。
我已启用 JSON 架构验证和必填字段,如下所述:https://www.danrigby.com/2018/08/27/enable-schema-validation-and-required-fields-in-logicapps/
我的 JSON 架构目前如下所示:
{
"anyOf": [
{
"required": [
"delay"
]
},
{
"required": [
"startTime"
]
}
],
"properties": {
"callbackUrl": {
"type": "string"
},
"delay": {
"default": 0,
"minimum": 0,
"type": "integer"
},
"startTime": {
"type": "string"
}
},
"required": [
"callbackUrl"
],
"type": "object"
}
我也试过用 defaultValue
替换 default
但没有成功。
我希望 delay
在不存在时填充为 0,但它在 Azure 逻辑应用程序工作流中被解释为 null
,导致以下布尔条件失败,例如 delay is greater than 0
因为他们不希望评估空值。
我相信 JSON 架构仅用于此处的验证,因为它在许多情况下都是如此。 default
属性 被许多实现忽略,如 official docs.
相反,您可以在 null
if (equals(triggerBody()?['delay'], null), triggerBody()?['delay'], 0)