malli

J 2025-11-13T16:25:18.474519Z

Hi guys! I have this schema:

(def s
  [:map
    [:x :string]
    [:y {:optional true :gen/return "hello"} :string]]
I'm wondering if there is a way to force the field y be always generate with malli.gen

2025-11-13T16:36:16.286169Z

if it always generates :y, when do you test that it doesn't exist?

J 2025-11-13T17:04:29.468889Z

Yes maybe not always

2025-11-13T17:06:24.065859Z

I mean that the purpose of test generation is to test all permutations of the potential data. if you want to cover the part where it doesn't do that, maybe generate only the :x schema and add in the :y schema after

👍 1
Ben Sless 2025-11-13T17:27:46.309029Z

I think the gen should be attached to the string and not the map entry

2025-11-13T22:26:11.744489Z

Not supported at the moment IIRC, either use :gen/fmap to assoc the entry back on or :gen/schema to override the entire schema. It would be easy to support a :gen/optional field on the map entry, please open a ticket if you're interested in that.

(def s
  [:map
    {:gen/schema [:map [:x :string] [:y :string]]}
    [:x :string]
    [:y {:optional true} :string]]
(ideally this would be supported:)
(def s
  [:map
    [:x :string]
    [:y {:optional true :gen/optional false} :string]]