metosin / malli

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

`:map` with default key merged with `[:map {:closed true}]` results in virtually open map #931

Open jahson opened 1 year ago

jahson commented 1 year ago

I'm not really sure at the moment about what is correct behavior in this case, but resulting map is closed and thus should, probably, remove default key?

(def registry (merge (m/default-schemas) (mu/schemas)))
  (def Merged
    (m/schema
     [:merge
      [:map
       [:x :string]
       [::m/default [:map-of :keyword :any]]]
      [:map {:closed true}
       [:y :int]]]
     {:registry registry}))

  (m/validate Merged {:x "kikka", :y 6, :z "invalid"})
; => true

Seems to be related to https://github.com/metosin/malli/pull/871

ikitommi commented 1 year ago

Good point. Result of merge:

(m/deref Merged)
;[:map {:closed true} 
; [:x :string] 
; [:y :int]
; [:malli.core/default [:map-of :keyword :any]]]