【发布时间】:2018-08-01 00:53:42
【问题描述】:
我写了一个宏
(defmacro defendpoint [msg-type url-key schema]
`(defrecord ~msg-type []
Create
(create [entity#]
(s/validate ~schema entity#)
(create-entity (~url-key urls) entity#))))
我就是这样使用它的
(defendpoint Location :locations
{... my schema ...}})
(defendpoint LocationHierarchy :location-hierarchies
{... my schema ...}})
我第一次使用宏,它可以工作
(create (map->Location
{... data ...}))
=> { ... json response ...}
但是第二次失败了:
(create (map->LocationHierarchy
{... data ...}))
=> 1. Unhandled java.lang.IllegalArgumentException
No implementation of method: :spec of protocol:
#'schema.core/Schema found for class: ohds.client$fn__32303
我不确定为什么会这样。我希望第二次调用的工作方式与第一次相同,但在验证步骤中似乎存在错误。事实上,如果我从宏中删除 (s/validate...),它会按预期工作。所以我不确定这里到底发生了什么。
I've created a gist that shows the entire file I'm working with
【问题讨论】:
标签: clojure