Function check with Prismatic / schematic in Clojure
I have a very simple question about using Prismatic / schema to test functions. I have a schema for a single key map whose value is a function that takes a schema Bar
as its only argument and returns anything (used for side effects):
(require '[schema.core :as s]) (def Bar {:baz s/Int}) (def Action :???) (def Foo {:action Action})
The question is how to determine Action
? I've tried this:
(require '[schema.macros :as sm]) (def Action (sm/=> s/Any Bar))
This looks promising, but I cannot test it:
(s/explain Action) ;=> (=> Any {:baz Int}) ;; This should fail (s/validate Foo {:action :anything-goes}) ;=> {:action :anything-goes}
What am I doing wrong here?
I've read the docs and tests in core_test , but I can't figure out how to do this.
source to share
I found this: https://github.com/Prismatic/schema/blob/a21cc0113ed497f6410c55d92d9088bd710f0b47/src/cljx/schema/core.cljx#L888
So it would be something like:
(def Action (s/make-fn-schema s/Any [[Bar]]))
Although the documentation says it:
Function diagrams are currently purely descriptive; they check any function regardless of the actual input and output types
source to share