我对s/union的理解是,你会用它来结合同一层级的两个spec,例如在(s/union ::user/private ::user/public)。
我想要的结构如下,类似于这个JSON结构
{"TransactItems": [{"Get": {"TableName": "string", "Key": "string"}}]}
(s/def ::transact-schema (s/schema [::TableName ::Item ::Key ::ConditionExpression]))
(s/def ::Get (s/select ::transact-schema [::TableName ::Key])))
(s/def ::ConditionCheck (s/select ::transact-schema [::TableName ::Key ::ConditionExpression])))
(s/def ::Put (s/select ::transact-schema [::TableName ::Item])))
(s/def ::TransactGetItem (s/schema [::Get])))
(s/def ::TransactWriteItem (s/schema [::ConditionCheck ::Put])))
(s/def ::TransactItems
(s/or :get (s/coll-of ::TransactGetItem :kind vector?)
:write (s/coll-of ::TransactWriteItem :kind vector?))))
在此,我指定了“Get”的取值可以是内层级别的值(一个包含“TableName”和“Key”为键的映射)以及“TransactItems”的取值可以是外层级别的值(一个包含“Get”作为键的映射数组或包含“Put”和“ConditionCheck”作为键的映射数组)。
来源:
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html