Skip to content

Commit

Permalink
merge + closed bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenet committed Jan 6, 2025
1 parent 7e99a50 commit 93fa9a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/exoscale/coax.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,12 @@

(defn gen-coerce-merge
[[_ & spec-forms]]
(fn [x opts]
(fn [x {:as opts :keys [closed]}]
(if (map? x)
(reduce (fn [m spec-form]
;; for every spec-form coerce to new value;
;; we need to compare key by key what changed so that
;; defaults do not overwrite coerced values
(into m
(keep (fn [[spec v]]
;; new-val doesn't match default, keep it
(when-not (= (get x spec) v)
[spec v])))
(coerce spec-form x (assoc opts :closed true))))
x
spec-forms)
(into {}
(map (fn [spec-form]
(coerce spec-form x (assoc opts :closed closed))))
spec-forms)
:exoscale.coax/invalid)))

(defn gen-coerce-nilable
Expand Down
5 changes: 5 additions & 0 deletions test/exoscale/coax_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@
(sc/coerce ::merge2 {::foo "1" :foo "1" :bar "1" :c {:a 2}}))
"Leave out ok vals")

(is (= {::foo 1 :bar "1" :foo 1}
(sc/coerce ::merge2 {::foo "1" :foo "1" :bar "1" :c {:a 2}}
{:closed true}))
"Remove extras")

(is (= "garbage" (sc/coerce ::merge "garbage"))
"garbage is passthrough")

Expand Down

0 comments on commit 93fa9a6

Please sign in to comment.