Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2568,10 +2568,12 @@
(map? ?ast) (if-let [s (-lookup (:type ?ast) options)]
(let [r (when-let [r (:registry ?ast)] (-delayed-registry r from-ast))
options (cond-> options r (-update :registry #(mr/composite-registry r (or % (-registry options)))))
ast (cond-> ?ast r (-update :properties #(assoc % :registry (-property-registry r options identity))))]
(cond (and (into-schema? s) (-ast? s)) (-from-ast s ast options)
(into-schema? s) (-into-schema s (:properties ast) (-vmap #(from-ast % options) (:children ast)) options)
:else s))
ast (cond-> ?ast r (-update :properties #(assoc % :registry r)))]
(if (into-schema? s)
(if (-ast? s)
(-from-ast s ast options)
(-into-schema s (:properties ast) (-vmap #(from-ast % options) (:children ast)) options))
s))
(-fail! ::invalid-ast {:ast ?ast}))
:else (-fail! ::invalid-ast {:ast ?ast}))))

Expand Down
24 changes: 24 additions & 0 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3581,3 +3581,27 @@
(is (not (m/validate [:sequential {:min 11} :int] (eduction identity (range 10)))))
(is (not (m/validate [:seqable {:min 11} :int] (eduction identity (range 10)))))
(is (nil? (m/explain [:sequential {:min 9} :int] (eduction identity (range 10))))))

(deftest from-ast-delayed-registry-test
(let [form [:int {:registry {::foo :int}}]
forced? (volatile! false)
original-delayed-registry m/-delayed-registry
;;TODO refactor by providing custom IntoSchema constructor
s (with-redefs [m/-delayed-registry
(fn [m f]
(-> (original-delayed-registry m f)
(update-vals (fn [v]
(reify m/IntoSchema
(m/-into-schema [_ properties children options]
(vreset! forced? true)
(m/-into-schema v properties children options)))))))]
(m/from-ast (m/ast form)))
_ (is (not @forced?))
form' (m/form s)
_ (is @forced?)]
(is (= form form'))))

(comment
(m/from-ast (m/ast [:int {:registry {::foo :int}}]))
(m/form (m/from-ast (m/ast [:int {:registry {::foo :int}}])))
)