File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 129
129
[[_ & spec-forms]]
130
130
(fn [x {:as opts :keys [closed]}]
131
131
(if (map? x)
132
- (into (cond-> x closed empty)
133
- (map (fn [spec-form]
134
- (coerce spec-form x (assoc opts :closed true ))))
135
- spec-forms)
132
+ (if closed
133
+ (into {}
134
+ (map (fn [spec-form]
135
+ (coerce spec-form x (assoc opts :closed true ))))
136
+ spec-forms)
137
+ ; ; not closed, we also have to ensure we don't overwrite values with
138
+ ; ; more loose specs towards the end of the args (ex `any?`
139
+ (reduce (fn [m spec-form]
140
+ (into m
141
+ (remove (fn [[k v]]
142
+ (= (get x k) v)))
143
+ (coerce spec-form x (assoc opts :closed true ))))
144
+ x
145
+ spec-forms))
146
+
136
147
:exoscale.coax/invalid )))
137
148
138
149
(defn gen-coerce-nilable
Original file line number Diff line number Diff line change 373
373
374
374
(deftest test-or-conditions-in-unqualified-keys
375
375
(is (= (sc/coerce ::unqualified {:foo " 1" :bar " hi" })
376
+ {:foo 1 :bar " hi" }))
377
+
378
+ (is (= (sc/coerce ::unqualified {:foo " 1" :bar " hi" } {:closed true })
376
379
{:foo 1 :bar " hi" })))
377
380
378
381
(deftest test-closed-keys
402
405
any?))
403
406
(is (= {:foo 1 :bar " 1" :c {:a 2 }}
404
407
(sc/coerce ::merge {:foo " 1" :bar 1 :c {:a 2 }}))
405
- " Coerce new vals appropriately" )
408
+ " Coerce new vals appropriately 1 " )
406
409
407
410
(is (= {:foo 1 :bar " 1" :c {:a 2 }}
408
411
(sc/coerce ::merge {:foo 1 :bar " 1" :c {:a 2 }}))
409
412
" Leave out ok vals" )
410
413
411
414
(is (= {:foo 1 :bar " 1" :c {:a 2 }}
412
415
(sc/coerce ::merge {:foo " 1" :bar 1 :c {:a 2 }}))
413
- " Coerce new vals appropriately" )
416
+ " Coerce new vals appropriately 2 " )
414
417
415
418
(s/def ::merge2 (s/merge (s/keys :req [::foo ])
416
419
::unqualified ))
You can’t perform that action at this time.
0 commit comments