对象
对象是 JSON 数据的基本输入。
💡 常用对象 Usage
对象输入类型可被用于来存储任何基于键/值的数据,例如:
- 配置;
- 标签
- HTTP 响应;
- 字典/哈希映射;
- 等等。
在live demo 自助服务集线器页面,我们可以看到打开 terraform PR 以添加 S3 存储桶操作,其 policy
输入是对象输入。
应用程序接口定义
- Basic
- Select (Enum)
- Array
{
"myObjectInput": {
"title": "My object input",
"icon": "My icon",
"description": "My object input",
"type": "object",
"default": {
"myKey": "myValue"
}
}
}
{
"myObjectSelectInput": {
"title": "My object select input",
"icon": "My icon",
"description": "My object select input",
"type": "object",
"enum": [
{
"myKey": 1
},
{
"myKey": 2
}
]
}
}
{
"myObjectArrayInput": {
"title": "My object array input",
"icon": "My icon",
"description": "My object array input",
"type": "array",
"items": {
"type": "object"
}
}
}
Check out Port's API reference to learn more.
Terraform 定义
- Basic
- Array
resource "port_action" "myAction" {
# ...action properties
user_properties = {
object_props = {
"myObjectInput" = {
title = "My object input"
description = "My object input"
default = jsonencode({ "myKey" = "myValue" })
}
}
}
}
resource "port_action" "myAction" {
# ...action properties
user_properties = {
array_props = {
"myObjectArrayInput" = {
title = "My object array input"
description = "My object array input"
object_items = {}
}
}
}
}
验证对象
对象验证支持以下操作符:
properties
- 必须出现的键及其类型;additionalProperties
- 是否允许使用properties
中未定义的键,以及它们的类型;patternProperties
- 属性应遵循哪种 regex 模式
对象验证遵循 JSON 模式模型,请参阅JSON schema docs 了解所有可用验证
- Basic
- Array
- Terraform - coming soon
{
"myObjectInput": {
"title": "My object input",
"icon": "My icon",
"description": "My object input",
"type": "object",
"properties": {
"myRequiredProp": { "type": "number" }
},
"patternProperties": {
"^S_": { "type": "string" },
"^I_": { "type": "number" }
},
"additionalProperties": true
}
}
{
"myObjectArrayInput": {
"title": "My object array input",
"icon": "My icon",
"description": "My object array input",
"type": "array",
"items": {
"type": "object",
"properties": {
"myRequiredProp": { "type": "number" }
},
"patternProperties": {
"^S_": { "type": "string" },
"^I_": { "type": "number" }
},
"additionalProperties": true
}
}
}