This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
hi, should this be an error?
(plantuml/transform [:schema {:registry r} "Network"])
; Execution error (IllegalArgumentException) at malli.core/-property-registry (core.cljc:258).
; Don't know how to create ISeq from: malli.registry$composite_registry$reify__10480
I think the rule of thumb is everything inside a schema needs to be serializable. so no IntoSchema definitions, composite schemas etc., (they should all go in options). related https://github.com/metosin/malli/issues/1048
I am trying to visualize a schema that also has :time/instant so I build a custom registry with defaults, time + my schema . Also, I expected this to work but it does not
(plantuml/transform "Network" {:registry r})
; Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:136).
; :malli.core/invalid-schema
while I can do
(mg/generate "Network" {:registry r})
seems like I can
(plantuml/transform :int {:registry r})
so I guess the issue is with my schema + plantumlI made a reproducer for the issue I am getting with malli 0.16.1
(ns user
(:require [malli.experimental.time.generator]
[malli.experimental.time :as mt]
[malli.core :as m]
[malli.registry :as mr]
[malli.generator :as mg]
[malli.plantuml :as plantuml]
[malli.dot :as md]))
(def snm-schema {"Curve" [:enum :curve25519 :p256]})
(def r
(mr/composite-registry
m/default-registry
(mr/registry (mt/schemas))
(mr/registry snm-schema)))
(comment
(mg/generate "Curve" {:registry r})
;; => :p256
(plantuml/transform ["Curve"] {:registry r})
;; => Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:136).
;; :malli.core/invalid-schema
(md/transform ["Curve"] {:registry r})
;; => Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:136).
;; :malli.core/invalid-schema
)
Apparently the registry needs to be embedded in the schema atm.
(println (plantuml/transform [:schema {:registry {"Curve" [:enum :curve25519 :p256]}} "Curve"]))
@startuml
entity Curve {
[:enum :curve25519 :p256]
}
@enduml
@ambrosebs: can you help me figure out how to build a schema from vars? I have a bunch of and don't know how to build a schema from them . It worked with a map {"Curve" [:enum ... }
(def Curve [:enum :curve25519 :p256])
will this work if I have references?
(def KeyPair [:map {:title "Key pair"}
[:curve [:ref {:min 1 :max 1} #'Curve]]
and want to add KeyPair as well?So there's this separate feature for using vars as schemas, but I'm going to assume you want the simplest thing.
(def Curve [:enum :curve25519 :p256])
(def KeyPair [:map {:title "Key pair"}
[:curve [:ref {:min 1 :max 1} "Curve"]]])
[:schema {:registry {"Curve" Curve, "KeyPair" KeyPair}} ...]
yes, I would like to get this working - but was also curios to understand why / how it works and there are nota lot of docs
Have you seen the docs on recursive schemas? https://github.com/metosin/malli?tab=readme-ov-file#recursive-schemas
It's a bit more advanced than you need, but the second example shows that whenever schema sees a registry reference, it eagerly replaces it with the schema it's pointing to.
you can see a bit of how it works by using m/deref, which replaces a ref with its mapped schema.
(take 3 (iterate m/deref (m/schema [:schema {:registry {"Curve" [:enum :curve25519 :p256]}} "Curve"])))
([:schema {:registry {"Curve" [:enum :curve25519 :p256]}} "Curve"]
"Curve"
[:enum :curve25519 :p256])
a dereferenced schema remembers the registry it was defined with
(-> [:schema {:registry {"Curve" [:enum :curve25519 :p256]}} "Curve"]
m/deref-all
m/options
:registry
mr/-schemas
(select-keys ["Curve"]))
{"Curve" [:enum :curve25519 :p256]}