metosin / malli

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

Parser losing metadata? #1015

Open Frozenlock opened 3 months ago

Frozenlock commented 3 months ago

Looks like the parser is losing the metadata along the way.

(def id-schema
  [:and
   ;; Nested :and to be able to add metadata to generated content
   [:and {:gen/fmap #(with-meta % {:kw-id true})}
    [:cat {:gen/fmap vec}
     :keyword
     [:+ :string]]
    vector?]
   [:fn #(:kw-id (meta %))] ; <- causes issues with the parser?
   ])

(meta (mg/generate id-schema))
;=> {:kw-id true}

(m/parse id-schema (mg/generate id-schema))
;=> :malli.core/invalid

If you comment out the metadata test and try again, it works:

(def id-schema
  [:and
   ;; Nested :and to be able to add metadata to generated content
   [:and {:gen/fmap #(with-meta % {:kw-id true})}
    [:cat {:gen/fmap vec}
     :keyword
     [:+ :string]]
    vector?]
   ;[:fn #(:kw-id (meta %))] ; <- causes issues with the parser?
   ])

(m/parse id-schema (mg/generate id-schema))
;=> [:+_8X.u
 ["W3Iz5qe"
  "9r01WwNdDl91Gdzyk3QF7"
  "45BD4Z8qx6xa7ab5E5JbU6mLAv"
  "r01uuAvF6cmet7Kc964F7L"
  "BoUJv"
  "0q445EvwmMBj3JlaTYmT0n"]]
ikitommi commented 3 months ago

There hasn't been promised about retaining meta-data, but there could and should be.