Fork me on GitHub
#malli
<
2021-09-01
>
Célio14:09:18

Is there a way to customize the “missing required key” error message? For example, the code below returns the default missing key error message instead of something's wrong which makes sense because :error/message relates to the contents of :something, not to whether the key is present. It would be great if we could customize missing key errors.

(me/humanize (m/explain
              [:map
               [:something
                [:string {:error/message "something's wrong"}]]]
              {}))

dergutemoritz15:09:23

Have you tried putting it on the entry's props?

dergutemoritz15:09:49

as in:

[:something {:error/message "something's wrong"} :string]

Célio17:09:52

@U06GVE6NR Yes, the result is the same.

Doug Kirk18:09:27

What's the best way to specify a schema for a map with both fixed keys and dynamic keys? Conceptually what I'd like is something like this schema to specify that a step has a :run keyword and some dynamic keys, and a workflow has :name and :start keywords and some dynamic keys:

(def step
  [:and [:map [:run :qualified-keyword]]
        [:map-of :keyword [:map [:next :keyword]]]])

(def workflow
  [:and [:map [:name :string]
              [:start :keyword]]
        [:map-of :keyword step]])
The data has this shape:
{:name "my-workflow"
 :start :begin

 :begin
 {:run :app/init
  :ok {:next :do-work}
  :fail {:next :done}}

 :do-work
 {:run :app/process-queue
  :ok {:next :done}}

 :done
 {:run :app/cleanup}}}
The problem I've run into is that I need to #(apply dissoc % fixed-keys) before the :map-of schema is evaluated for any map matching this pattern. Maybe there's a better way?

ikitommi17:09:54

sorry, no, but there is an issue for that: https://github.com/metosin/malli/issues/43 @U09EGLJLB

👍 2
🙏 2