Fork me on GitHub
#malli
<
2020-05-28
>
ikitommi05:05:26

@jstuartmilne something like:

(m/accept
  [:map
   [:user map?]
   [:profile map?]
   [:nested [:map [:x [:tuple {:deleteMe true} string? string?]]]]
   [:token [string? {:deleteMe true}]]]
  (fn [schema children _ options]
    (if-not (:deleteMe (m/properties schema))
      (let [children (filterv (if (m/map-entries schema) last identity) children)]
        (m/into-schema (m/name schema) (m/properties schema) children options)))))
; => [:map [:user map?] [:profile map?] [:nested :map]]

ikitommi05:05:46

e.g. check if the schema has the property, remove if it has. if not, you have to remove the nil childs as it’s currently not valid syntax. There are two child syntaxes: the normal and the (map)entry-one. need to handled differently.

ikitommi05:05:20

that doesn’t drop the empty nodes, e.g. :map without any keys is valid, same with empty :tuple etc.

ikitommi10:05:21

anyone interested in doing malli.xml? something like:

(def User [:map [:users [:vector [:map [:user string?]]]]])

(m/decode User "<users><user>simo</user></users>" malli.xml/xml-transformer)
; => {:users [{:user "simo"}]}

(m/encode User {:users [{:user "simo"}]} malli.xml/xml-transformer)
; => "<users><user>simo</user></users>"

👍 8
sudakatux12:05:05

Thank u so much.Ive been struggling witth that