模式當我有一個記錄定義爲一個架構如下:從記錄模式映射Clojure中
(schema.core/defrecord Account [id :- schema/Uuid
short-id :- schema/Str
name :- schema/Str
created-at :- schema/Inst])
我如何提取申請將包含這些值的HashMap中的架構?
原因是HTTP服務接收地圖並自動將模式應用於它們,如果我只是使用帳戶,它會失敗,因爲地圖不是帳戶類型。
我試圖從解釋中提取,如:
(schema.core/explain Account)
但我得到的是不是一個真正的模式:
{:id Uuid,
:short-id Str,
:name Str,
:created-at Inst}
值是符號而不是類,因此,如果您嘗試使用它:
(schema.core/validate (last (schema.core/explain server.models.account.Account)) {})
你得到這個錯誤:
IllegalArgumentException No implementation of method: :spec of protocol: #'schema.core/Schema found for class: clojure.lang.Symbol clojure.core/-cache-protocol-fn (core_deftype.clj:568)
你問如何從一個記錄定義提取此模式,或如何構建地圖的等效模式? – fl00r
@ fl00r如何從記錄中提取它,以便我不必手動重新創建它。我會修改這個問題。 – Pablo