malli

Chip 2025-02-12T17:38:27.364419Z

Noob here. I want a single-source-of-truth document for my model. It needs to allow meta stuff at all levels; it's my version of https://en.wikipedia.org/wiki/Literate_programming. Not knowing any better, I codified my model in EDN (see image of formatted code).

{:version "1"
 :description "yada yada"
 :entities
 {:foo {...}
  :meta {...}} ; <============== everywhere
 :relationships
 {:bar {:baz {...}
        :meta {...}}}
 :targets ; <============ generation targets
 {:shared
  {:some-shared-generation-thing true
   :meta {...}}
  :dot {...}
  :datomic
  {:generate-lpg true
   :meta {...}}
  :malli ; <============ not so sure this makes sense
  {:meta
   {:conversation
    [:date "2025-02-12" :author "me"
     :md "*Super* don't know what I'm doing."]
    ...}
   ...}}}
I am generating DOT and Datomic schema EDN from the model. On principle — not intelligence — I started generating malli from that same EDN. Something didn't feel right. Me thinks, "this ignorance might not be bliss." The malli README intensifies the thought. Can I write my meta-infested, single-source-of-truth in malli and generate from there?

2025-02-12T17:56:05.233699Z

You can use properties to add metadata to malli schemas, then pull them out with m/properties.

(def Age
  [:and
   {:title "Age"
    :description "It's an age"
    :json-schema/example 20}
   :int [:> 18]])

(m/properties Age)
; => {:title "Age"
;     :description "It's an age"
;     :json-schema/example 20}

2025-02-12T17:58:08.282519Z

See the schema -> swagger transformation for an example using metadata: https://github.com/metosin/malli/blob/5e18221868bfe7fe7810fd91d452d686c34c5290/src/malli/swagger.cljc

Chip 2025-02-12T18:08:13.172049Z

Thank you. Please forgive my super-uninformed question: Do you see any reason not to use malli to create my single source of truth? Asked another way, are there modeling use cases for which malli is less recommended? Again, thanks.

2025-02-12T18:34:05.293829Z

If you're just describing data shapes then malli is probably going to work fine. OTOH it's going to be harder to write a new translator from malli schemas to some other format than to start with your own restricted language.

2025-02-12T18:35:21.125359Z

if you write a translator from your EDN format to malli then you can access all the other integrations that have been built via malli.

2025-02-12T18:35:58.377849Z

which sounds like what you've already done.

Chip 2025-02-12T18:53:37.663149Z

My EDN->malli translator is lousy. I'll build it out if I have to. Is there a list of integrations that have been built via malli? I see https://github.com/metosin/malli?tab=readme-ov-file#dot. Is Datomic only available via https://github.com/licht1stein/malli-datomic?

2025-02-12T18:56:13.728039Z

The readme lists a few. There's a bunch around web programming floating about, like in reitit.

Chip 2025-02-12T18:56:55.378639Z

Thank you

Chip 2025-02-12T17:47:01.946229Z

Chip 2025-02-12T17:47:41.339269Z

TIL about code snippets