Fork me on GitHub
#malli
<
2024-02-06
>
steven kent15:02:11

Hello, I'm trying to use a :fn schema that uses a function that is locally defined in the same file. (*def* file-test2 [:fn '(*fn* [s] (test-fn s))]) When I try to validate using this schema an sci exception is thrown Could not resolve symbol: test-fn I've tested test-fn in the REPL and it works as I expect it to. How to get Malli to recognize the symbol? Thank you

borkdude15:02:50

Just don't use the quote

borkdude15:02:02

unless you want to serialize the function

zeitstein18:02:04

I have a very basic question. Say I have a set user-roles used in my code. In malli this would be e.g. (def UserRoles (into [:enum] user-roles)). If I want to avoid duplication, do I handle this as described or do I go the other way around: use the malli schema as the source of truth then either use m/validate (don't think it can replace a set for every use case) or (def user-roles (set (rest UserRoles))) ? It's just data, so both work, but wondering how you approach this.

Franco Gasperino19:02:06

I've applied them into the schema.

(def user-roles [1 2 3])
(def schema-1
  [:role (into [:enum] user-roles)])
also allows variations...
(def schema-2
  [:role (into [:enum] (conj user-roles 4))])

gratitude 1
tony.kay20:02:05

Malli support in Guardrails has been released. See #C06MAR553

👍 5
🎉 4
1