我已经定义了以下架构:
(s/defschema Card
{:cardNumber s/Str
:cvv s/Str
:creditCardMonthValidity s/Str
:creditCardYearValidity s/Str
:cpf s/Str
:name s/Str
:phoneNumber s/Str})
然后在一条路线中,我在 JSON 响应中使用相同的键:
(GET "/card" []
:summary "fetches card info given the access token & checkout id"
:query-params [accessToken :- String checkoutId :- String]
:return Card
(let [checkout (CheckoutApi/show checkoutId accessToken)
card (.getCard checkout)
contact (.getContact checkout)
(ok {:cardNumber (.getAccountNumber card)
:cvv "000"
:creditCardMonthValidity (.getExpiryMonth card)
:creditCardYearValidity (.getExpiryYear card)
:cpf (.getNationalID contact)
:name (.getFirstName contact)
:phoneNumber (.getPhoneNumber contact)})]))
有没有一种优雅的方法来避免键名的重复?类似于构造函数的方法,我可以只传递值吗?(也许以某种特定的顺序)