This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-04
Channels
- # atom-editor (2)
- # babashka (39)
- # beginners (123)
- # calva (90)
- # cider (57)
- # clojure (103)
- # clojure-australia (13)
- # clojure-europe (38)
- # clojure-france (3)
- # clojure-italy (13)
- # clojure-nl (7)
- # clojure-norway (2)
- # clojure-seattle (1)
- # clojure-uk (22)
- # clojurescript (28)
- # conjure (20)
- # cursive (2)
- # datascript (1)
- # datomic (20)
- # depstar (23)
- # emacs (1)
- # events (2)
- # graphql (12)
- # honeysql (4)
- # jobs (2)
- # kaocha (2)
- # malli (14)
- # music (2)
- # off-topic (103)
- # pathom (8)
- # polylith (7)
- # quil (3)
- # reagent (7)
- # reitit (2)
- # remote-jobs (1)
- # shadow-cljs (55)
- # slack-help (4)
- # spacemacs (29)
- # xtdb (16)
How can I read the properties of attributes in a map. E.g. the description of one-attr in this example
(def test-schema
(malli/schema [:map {:description "test schema desc."}
[:one-attr {:description "attr description"} string?]]))
(malli/properties test-schema) ;; => {:description "test schema desc."}
(malli/properties (mu/get test-schema :one-attr)) ;; => nil
@daniel415 try (mu/find schema key)
and you can iterate the child entries with m/children
The mu/get
does work and gives me the correct schema back but just m/properties
is not returning anything. (only for maps)
And m/children
is not working in my example?
(-> (malli/schema [:map {:description "test schema desc."}
[:one-attr {:description "attr description"} string?]])
(mu/find :one-attr)
malli/children)
return this error
Execution error (ExceptionInfo) at malli.impl.util/-fail! (util.cljc:12).
:malli.core/invalid-schema {:schema :one-attr}
also, this should hold:
(-> [:map [:x [:int {:default 1}]]]
(m/get :x)
(m/properties))
;; -> {:default 1}
Hmm, your example works. But when I simply have string?
or so it doesn't work.
(-> [:map [:x {:default 1} string?]]
(mu/get :x)
(m/properties))
;; => nil
So this is the equivalent that works:
(-> [:map [:x [:string {:default 1}]]]
(mu/get :x)
(m/properties))
;; => {:default 1}
string?
doesn’t have properties. is is short format for [string?]
. You can add properties to it too, e.g. [string? {:default 1}]
. Full example:
(-> [:map [:x [string? {:default 1}]]]
(mu/get :x)
(m/properties))
;; => {:default 1}
(still not at malli repl, just guessing what it returns)now at the repl:
(def Schema
[:map {:in "map"}
[:x {:in "entry"} [:string {:in "value"}]]])
(m/properties Schema)
;; => {:in "map"}
(-> Schema
(mu/find :x)
(second))
;; => {:in "entry"}
(-> Schema
(mu/get :x)
(m/properties))
;; => {:in "value"}'
some helpers:
(defn entry-properties [schema key]
(-> schema (mu/find key) (second)))
(defn value-properties [schema key]
(-> schema (mu/get key) (m/properties)))
(m/properties Schema) ;; => {:in "map"}
(entry-properties Schema :x) ;; => {:in "entry"}
(value-properties Schema :x) ;; => {:in "value}