Skip to content

Commit

Permalink
Merge pull request #574 from metosin/fix-schema-explain
Browse files Browse the repository at this point in the history
fixes #573
  • Loading branch information
ikitommi authored Nov 17, 2021
2 parents 2403362 + 6305b6d commit a9840be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@
(if id (-ast {:type type, :value id} (-properties this) (-options this)) (-to-child-ast this)))
Schema
(-validator [_] (-validator child))
(-explainer [_ path] (-explainer child path))
(-explainer [_ path] (-explainer child (conj path 0)))
(-parser [_] (-parser child))
(-unparser [_] (-unparser child))
(-transformer [this transformer method options]
Expand Down
29 changes: 18 additions & 11 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@

(deftest parse-entries-test
(let [entry-parser (m/-create-entry-parser
[[:x int?]
::x
"x"
[::y {:optional true}]
[:y {:optional true, :title "boolean"} boolean?]]
{:naked-keys true}
{:registry (merge (m/default-schemas) {::x int?, "x" int?, ::y int?})})]
[[:x int?]
::x
"x"
[::y {:optional true}]
[:y {:optional true, :title "boolean"} boolean?]]
{:naked-keys true}
{:registry (merge (m/default-schemas) {::x int?, "x" int?, ::y int?})})]
(testing "forms"
(is (= [[:x 'int?]
::x
Expand Down Expand Up @@ -565,7 +565,7 @@
(is (results= {:schema ConsCell
:value [1 [2]]
:errors [{:in [1]
:path [0 1 0 0]
:path [0 0 0 1 0 0]
:schema (mu/get-in ConsCell [0 0 0])
:type :malli.core/tuple-size
:value [2]}]}
Expand Down Expand Up @@ -634,6 +634,13 @@
::ping]
["ping" ["ping" nil]])))))

(testing "schema"
(is (form= :int
(as-> [:schema :int] $
(m/explain $ "1")
(let [{:keys [schema] [{:keys [path]}] :errors} $]
(mu/get-in schema path))))))

(testing "malli.core/schema"
(is (= [::m/schema {:registry {::cons [:maybe [:tuple 'int? [:ref ::cons]]]}}
::cons]
Expand Down Expand Up @@ -662,9 +669,9 @@
(is (nil? (m/explain schema 1)))
(is (results= {:schema schema
:value -1
:errors [{:path [0 0] :in [] :schema pos-int?, :value -1}
{:path [0 1], :in [], :schema pos-int?, :value -1}
{:path [0 2], :in [], :schema pos-int?, :value -1}]}
:errors [{:path [0 0 0 0 0 0] :in [] :schema pos-int?, :value -1}
{:path [0 1 0 0 0], :in [], :schema pos-int?, :value -1}
{:path [0 2 0 0], :in [], :schema pos-int?, :value -1}]}

(m/explain schema -1)))

Expand Down
4 changes: 2 additions & 2 deletions test/malli/util_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@
[:x [:vector
[:set
[:sequential
[:tuple int? [:map [:y [:maybe boolean?]]]]]]]]])
[:x 0 0 0 1 :y 0])))
[:tuple int? [:map [:y [:maybe [:schema [::m/schema boolean?]]]]]]]]]]])
[:x 0 0 0 1 :y 0 0 0])))
(is (mu/equals (mu/get-in
[:map
[:x [:vector
Expand Down

0 comments on commit a9840be

Please sign in to comment.