Skip to content

Instantly share code, notes, and snippets.

@ikitommi
Last active Apr 5, 2020
Embed
What would you like to do?
Documenting malli keys and values
(require '[malli.core :as m])
;; using :and
(def Name
[:and {:documentation "Human name"} string?])
;; adding props to predicate schema
(def Name
[string? {:documentation "Human name"}])
;; the alternative map-syntax (https://github.com/metosin/malli/issues/178)
(def Name
(m/schema
{:type string?
:properties {:description "Human name"}}))
;; different options of documenting keys and values
[:map
;; spec-like coupling of keys and values, not supported yet https://github.com/metosin/malli/issues/14
:human/name
;; adding props to keys, see https://github.com/metosin/malli/issues/86
[:human/name {:description "Human name"} string?]
[:human/name {:description "Human name"} Name]
;; adding props to map values
[:human/name [:and {:description "Human name"} string?]]
[:human/name [string? {:description "Human name"}]]
[:human/name Name]]
;;
;; documenting values with and
;;
(def Human
[:map
[:human/name [:and {:description "Human name"} string?]]
[:human/age [:and {:description "Human age"} int?]]])
(doseq [[k _ s] (m/map-entries Human)]
(println k "->" (-> s m/properties :description)))
;:human/name -> Human name
;:human/age -> Human age
;;
;; documenting values with pridicate schema properties
;;
(def Human
[:map
[:human/name [string? {:description "Human name"}]]
[:human/age [int? {:description "Human age"}]]])
(doseq [[k _ s] (m/map-entries Human)]
(println k "->" (-> s m/properties :description)))
;:human/name -> Human name
;:human/age -> Human age
;;
;; documenting keys
;;
(def Human
[:map
[:human/name {:description "Human name"} string?]
[:human/age {:description "Human age"} int?]])
(doseq [[k p _] (m/map-entries Human)]
(println k "->" (-> p :description)))
;:human/name -> Human name
;:human/age -> Human age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment