我对 s/union 的理解是,您可以使用它来组合处于同一层次的两个规范,如在 (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)
: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