Skip to content

Commit 8cb2c11

Browse files
committed
propagate options to 1-child -reducing, disallow 0-child
1 parent 6a2d9bd commit 8cb2c11

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/malli/util.cljc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@
378378
;;
379379

380380
(defn -reducing [f]
381-
(fn [_ [first & rest :as children] options]
382-
(let [children (mapv #(m/schema % options) children)]
381+
(fn [_ children options]
382+
(let [[first & rest :as children] (mapv #(m/schema % options) children)]
383383
[children (mapv m/form children) (delay (reduce #(f %1 %2 options) first rest))])))
384384

385385
(defn -applying [f]
@@ -390,8 +390,8 @@
390390

391391
(defn -util-schema [m] (m/-proxy-schema m))
392392

393-
(defn -merge [] (-util-schema {:type :merge, :fn (-reducing merge)}))
394-
(defn -union [] (-util-schema {:type :union, :fn (-reducing union)}))
393+
(defn -merge [] (-util-schema {:type :merge, :fn (-reducing merge), :min 1}))
394+
(defn -union [] (-util-schema {:type :union, :fn (-reducing union), :min 1}))
395395
(defn -select-keys [] (-util-schema {:type :select-keys, :childs 1, :min 2, :max 2, :fn (-applying select-keys)}))
396396

397397
(defn schemas [] {:merge (-merge)

test/malli/util_test.cljc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,3 +1112,15 @@
11121112
{}
11131113
{:registry (merge (mu/schemas) (m/default-schemas))}
11141114
(mt/default-value-transformer {::mt/add-optional-keys true})))))
1115+
1116+
(deftest -reducing-test
1117+
(is (= :map (m/form (m/deref-all (m/schema [:merge [:merge :map]] {:registry (merge (mu/schemas) (m/default-schemas))})))))
1118+
(is (= :map (m/form (m/deref-all (m/schema [:union [:union :map]] {:registry (merge (mu/schemas) (m/default-schemas))})))))
1119+
(is (thrown-with-msg?
1120+
#?(:clj Exception, :cljs js/Error)
1121+
#":malli\.core/child-error"
1122+
(m/schema :merge {:registry (merge (mu/schemas) (m/default-schemas))})))
1123+
(is (thrown-with-msg?
1124+
#?(:clj Exception, :cljs js/Error)
1125+
#":malli\.core/child-error"
1126+
(m/schema :union {:registry (merge (mu/schemas) (m/default-schemas))}))))

0 commit comments

Comments
 (0)