Fork me on GitHub
#malli
<
2023-09-08
>
Ferdinand Beyer14:09:54

How can I use schemas from my custom registry in malli instrumentation? I have a namespace with a registry var, which is a mr/composite-registry. When I pass {:registry registry} as options to Malli functions, this works as expected. I now want to annotate functions like this, and use !:

(defn my-func
  {:malli/schema [:=> [:cat :custom-schema] :any]}
  [val])
I’ve tried to use (mr/set-default-registry! registry) before calling start!, and using [:=> {:registry registry} [:cat :custom-schema] :any], but both did not work (throws :invalid-schema). I also tried (! {:registry registry}). The only thing that did work is:
(defn my-func
  {:malli/schema (malli.core/schema [:=> [:cat :custom-schema] :any] {:registry registry})}
  [val])
Is that the recommended way to do it?

Ferdinand Beyer14:09:13

I was hoping to keep my metadata as plain data, without needing to require malli.core.

Ferdinand Beyer14:09:58

Argh. I found out that my custom start! that calls set-default-registry! is actually never called. It does work. Sorry for the noise 😇

👍 2
fuad09:09:45

Out of curiosity: where/when do you call set-default-registry? I tried using the default registry lately but moved away from it when I hit some load ordering problems.

Ferdinand Beyer12:09:53

In development, I just call set-default-registry! followed by malli.dev/start!. My custom registry is a composite-registry of default-schemas and mutable-registry. The mutable registry points to an atom where I assoc my schemas to. I first used default-registry instead of default-schemas, which does not work when using set-default-registry! because of infinite recursion. My production code does not change the default-registry, but passes the custom registry using the :registry option