Fork me on GitHub
Yehonathan Sharvit10:04:18

Hello, We are building an automatic form generator based on Malli. The form generator input is made of: • A malli schema • A structural description of the form The structure of the form is not necessarily the same as the structure of the data. Here is a example

{:schema [:map 
          [:username {:title "Username"} :string]
          [:email {:title "Email"
                   :description "The business email of the user"}
          [:personal [:map 
                      [:age {:title "Age"
                             :description "The age of the user"} :int]]]]
 :ui {:sections [{:title "General"
                  :fields [{:path [:username]}]}
                 {:title "Details"
                  :fields [{:path [:personal :age]}]}]}}
Now, my question is: is there a way to retrieve the schema that corresponds to a map field? For instance the schema that correspond to the [:personal :age] field.


sure, but there can be many schemas behind a path, if there is an :and or :or. but if you know what you are doing, you can just the the first one, like this:

(defn schema-in [?schema path]
  (let [schema (m/schema ?schema)]
    (->> (mu/in->paths schema path) (first) (mu/get-in schema))))

  [:username :string]
  [:email :string]
  [:personal [:map
              [:age :int]]]]
 [:personal :age])
; => :int


btw, just doing the same thing in a projects (again), would like to push some parts back to the library

Yehonathan Sharvit11:04:35

What exactly are you doing in your project? UI generation?


yes, two cases: 1. technical ui’s for admin/prototyping, directly from malli schemas 2. having large amount of dynamic forms & rules in project(s) => need both utilities for malli-backed form components and some data-oriented generic form-markup, “the ui-schema” … looking at your example, you are doing 2 too and I know there are many others doing that, looking forward to see if there could be something reusable / shared with these.

👍 1
Yehonathan Sharvit16:04:09

Have you found a way to deal with :multi?