我想定义一个模式,其中有一个 ListNestedAttribute,其中包含对象列表。在这些对象中,一个属性是动态的,因为它包含某种形式的任意对象。我会使用动态对象,但集合中不支持该对象。
resp.Schema = schema.Schema {
Attributes: map[string]schema.Attribute {
"my_list": schema.ListNestedAttributes {
Required: true,
NestedObject: schema.NestedAttributeObject {
Attributes: map[string]schema.Attribute {
"config": schema.Something {
}
}
}
}
}
}
这里我想知道
Something
应该是什么,或者我如何要求用户提供元素列表,其中每个元素都有一个名为 config 的属性,并且可以包含任意值。这可能吗?
tftypes 不支持泛型。为了与您正在使用的模式中的
list(object)
兼容,需要一个带有 tftypes
的相应结构和用于转换的 map[string]attr.Type{}
,并且这些也会导致使用泛型的问题,因为它们都已经定义了类型。