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}
try removing the last m/children
mu/find
should return the entry tuple, props being the second value
also, this should hold:
(-> [:map [:x [:int {:default 1}]]]
(m/get :x)
(m/properties))
;; -> {:default 1}
coding blind from a phone, might contain errors :)
but: maps, map entries and map entry values can all have properties
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}
OK, thank you very much. Now it's clear. I wasn't aware that string?
is shorthand for [string?]
and also didn't really think about the difference between entry and value properties. Makes sense now ๐