Last active
April 5, 2020 16:38
-
-
Save ikitommi/7c26aebf2b0f58d58432c884c8a55b5a to your computer and use it in GitHub Desktop.
Documenting malli keys and values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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