使用Clojure中的Prismatic/schema进行函数验证

Jos*_*ver 3 clojure plumatic-schema

关于使用Prismatic/schema来验证函数,我有一个非常简单的问题.我有一个具有单个键的映射的模式,其值是一个函数,它将Bar模式作为其单个参数并返回任何内容(用于副作用):

(require '[schema.core :as s])

(def Bar {:baz s/Int})
(def Action :???)
(def Foo {:action Action})
Run Code Online (Sandbox Code Playgroud)

问题是,我该如何定义Action?我试过这个:

(require '[schema.macros :as sm])

(def Action (sm/=> s/Any Bar))
Run Code Online (Sandbox Code Playgroud)

这看起来很有希望,但我不能让它失败验证:

(s/explain Action)
;=> (=> Any {:baz Int})

;; This should fail    
(s/validate Foo {:action :anything-goes})
;=> {:action :anything-goes}
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

我在core_test中阅读了文档和测试,但我无法弄清楚如何做到这一点.

Tom*_*ing 9

我发现了这个:https://github.com/Prismatic/schema/blob/a21cc0113ed497f6410c55d92d9088bd710f0b47/src/cljx/schema/core.cljx#L888

所以它会是这样的:

(def Action (s/make-fn-schema s/Any [[Bar]]))
Run Code Online (Sandbox Code Playgroud)

虽然,文档确实这样说:

目前,函数模式纯粹是描述性的; 无论实际的输入和输出类型如何,它们都会对任何函数进行验证