metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

`strip-extra-keys-transformer` behavior changed after version 0.10.3 #930

Closed jahson closed 10 months ago

jahson commented 10 months ago

Hi! Today I've discovered that after 0.10.3 strip-extra-keys-transformer changed its behavior:

[metosin/malli "0.10.2"]

(m/decode
  [:map]
  {1 1, 2 "2", "3" 3, "4" "4"}
  (mt/strip-extra-keys-transformer))
; => {1 1, 2 "2", "3" 3, "4" "4"}

[metosin/malli "0.10.3"]

(m/decode
 [:map]
 {1 1, 2 "2", "3" 3, "4" "4"}
 (mt/strip-extra-keys-transformer))
; => {}

It is for sure related to https://github.com/metosin/malli/blob/master/CHANGELOG.md#0103-2023-03-18 and https://github.com/metosin/malli/pull/871

ikitommi commented 10 months ago

in https://github.com/metosin/malli/pull/871/commits/0e5b5e3ac56479f75c812c1320ac1f1ebfba8f76:

  (testing "extra keys from :map are stripped"
    (is (= {:x 1, :y 2}
           (m/decode
            [:map [:x :int] [:y :int]]
            {:x 1, :y 2, :z 3}
            (mt/strip-extra-keys-transformer)))))

so, this seems intentional, but should have been part of CHANGELOG as breaking.

not to strip keys, you can either:

;; explicitly open map
(m/decode
 [:map {:closed false}]
 {:x 1, :y 2, :z 3}
 (mt/strip-extra-keys-transformer))
; => {:x 1, :y 2, :z 3}

or:

;; anything goes
(m/decode
 [:map [::m/default :any]]
 {:x 1, :y 2, :z 3}
 (mt/strip-extra-keys-transformer))
; => {:x 1, :y 2, :z 3}
ikitommi commented 10 months ago

post-fixed the CHANGELOG for 0.10.3 for this:

https://github.com/metosin/malli/commit/e3631e4a4c9f8190c101d3d51967a53fc00815de & https://github.com/metosin/malli/commit/23f0c02d90115a96fda5c37a5cb2c7e32b75a60e