Fork me on GitHub
#malli
<
2021-12-23
>
Noah Bogart15:12:16

#re-frame has the function ->interceptor which has a parameter list of [& {:as m :keys [id before after]}] , which uses this new feature: https://clojure.org/news/2021/03/18/apis-serving-people-and-programs. how can i represent this in a malli function schema?

Noah Bogart16:12:45

i have cobbled together this, but it feels pretty hacky, lol:

(m/=> ->interceptor
      [:=>
       [:cat
        [:or
         [:and
          [:map
           [:id qualified-keyword?]
           [:before {:optional true} fn?]
           [:after {:optional true} fn?]]
          [:fn (fn [{:keys [before after]}] (or before after))]]
         [:and [:catn
                [:id [:cat [:= :id] qualified-keyword?]]
                [:before [:? [:cat [:= :before] fn?]]]
                [:after [:? [:cat [:= :after] fn?]]]]
          [:fn (fn [[_ & args]] (pos? (count args)))]]]]
       :any])

Noah Bogart16:12:24

is there a way to make generative testing work with defn schemas like this? (mi/check) reports there’s no generator attached to this schema

Noah Bogart16:12:23

Execution error (ExceptionInfo) at malli.core/-fail! (core.cljc:137).
:malli.generator/no-generator {:options {:malli.core/function-checker #function[malli.generator/function-checker], :malli.generator/recursion {[:and [:map [:id qualified-keyword?] [:before {:optional true} fn?] [:after {:optional true} fn?]] [:fn #function[executor.interceptor/eval70188/fn--70190]]] 1, [:map [:id qualified-keyword?] [:before {:optional true} fn?] [:after {:optional true} fn?]] 1}}, :schema fn?}