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?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}
See the schema -> swagger transformation for an example using metadata: https://github.com/metosin/malli/blob/5e18221868bfe7fe7810fd91d452d686c34c5290/src/malli/swagger.cljc
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.
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.
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.
which sounds like what you've already done.
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?
The readme lists a few. There's a bunch around web programming floating about, like in reitit.
Thank you
TIL about code snippets