What's the preferred way to do generator overrides? e.g. I have a deeply nested multi in my schema and I'd like to force it to pick a particular branch for generation. To be clear, I mean from tests. Rather than on the schema itself.
There's no way to manipulate the generator without changing the schema. But there are plenty of ways to do the latter from tests if your registries are customizable.
It would be neat to be able to provide a custom generator for a ref or a path.
Yes, that would be great. I think spec ends up getting this quite wrong, especially with multi, as the overrides don't end up working correctly.
I wonder if it would be hard to do this in user land for malli
Try something like this:
(with-redefs-fn
{#'malli.generator/-create
(let [orig @#'malli.generator/-create]
(fn [s o]
(if (= ::schema-to-override (m/-ref s))
custom-generator
(orig s o)))}
#(m/generate ...))if your registry is a map you could also just update the options map: (update-in options [:registry ::schema-to-override] m/-update-properties assoc :gen/gen custom-generator)
Or use the right kind of registry that will locally shadow just one name from the global registry.
(m/generate schema {:registry (mr/composite-registry {::schema-to-override (m/-update-properties (m/deref (m/schema ::schema-to-override)) assoc :gen/gen custom-generator)}) m/default-registry)})})
both untested