From 2f554cd4c2d815e8b06c9cc3b590082207ccbbe1 Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:27:44 +0300 Subject: [PATCH 01/10] Remove unnecessary whitespace --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d5493d725..039a7ffa5 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Data-driven Schemas for Clojure/Script and [babashka](#babashka). - [Schema Transformations](#schema-Transformation) to [JSON Schema](#json-schema), [Swagger2](#swagger2), and [descriptions in english](#description) - [Multi-schemas](#multi-schemas), [Recursive Schemas](#recursive-schemas) and [Default values](#default-values) - [Function Schemas](docs/function-schemas.md) with dynamic and static schema checking - - Integrates with both [clj-kondo](#clj-kondo) and [Typed Clojure](#static-type-checking-via-typed-clojure) + - Integrates with both [clj-kondo](#clj-kondo) and [Typed Clojure](#static-type-checking-via-typed-clojure) - Visualizing Schemas with [DOT](#dot) and [PlantUML](#plantuml) - Pretty [development time errors](#pretty-errors) - [Fast](#performance) @@ -840,7 +840,7 @@ The first argument to `:error/fn` is a map with keys: - `:negated` (optional), a function returning the explanation of `(m/explain [:not schema] value)`. If provided, then we are explaining the failure of negating this schema via `(m/explain [:not schema] value)`. Note in this scenario, `(m/validate schema value)` is true. - If returning a string, + If returning a string, the resulting error message will be negated by the `:error/fn` caller in the same way as `:error/message`. Returning `(negated string)` disables this behavior and `string` is used as the negated error message. ```clojure @@ -1054,7 +1054,7 @@ For pretty development-time error printing, try `malli.dev.pretty/explain` Two-way schema-driven value transformations with `m/decode` and `m/encode` using a `Transformer` instance. -Default Transformers include: +Default Transformers include: | name | description | |:----------------------------------|-----------------------------------------------------| @@ -2018,7 +2018,7 @@ to recursive variables for better-behaving generators: ::cons] ;; produces the same generator as the "unfolded" [:maybe [:tuple pos-int? [:schema {:registry {::cons [:maybe [:tuple pos-int? [:ref ::cons]]]}} ::cons]]] -;; while +;; while [:schema {:registry {::cons [:maybe [:tuple pos-int? [:ref ::cons]]]}} [:ref ::cons]] ;; has a direct correspondance to the following generator: @@ -2087,7 +2087,7 @@ Schemas can be used to generate values: {:seed 10}) ; => "kikka" -;; :gen/fmap +;; :gen/fmap (mg/generate [:and {:gen/fmap (partial str "kikka_")} string?] {:seed 10, :size 10}) @@ -2286,10 +2286,10 @@ Sample-data can be type-hinted with `::mp/hint`: :b {:b 2, :c 1} :c {:b 3} :d nil}]) -;[:map-of -; :keyword -; [:maybe [:map -; [:b :int] +;[:map-of +; :keyword +; [:maybe [:map +; [:b :int] ; [:c {:optional true} :int]]]] ``` From ff6a85a3a3eebc34ea41e70779e3cb28db557eb7 Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:27:58 +0300 Subject: [PATCH 02/10] Fix expected result --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 039a7ffa5..052692847 100644 --- a/README.md +++ b/README.md @@ -518,7 +518,7 @@ and `:?`, `:*`, `:+` & `:repeat` for repetition: (m/explain [:* [:catn [:prop string?] [:val [:altn [:s string?] [:b boolean?]]]]] ["-server" "foo" "-verbose" 11 "-user" "joe"]) -;; => {:schema [:* [:map [:prop string?] [:val [:map [:s string?] [:b boolean?]]]]], +;; => {:schema [:* [:catn [:prop string?] [:val [:altn [:s string?] [:b boolean?]]]]], ;; :value ["-server" "foo" "-verbose" 11 "-user" "joe"], ;; :errors ({:path [0 :val :s], :in [3], :schema string?, :value 11} ;; {:path [0 :val :b], :in [3], :schema boolean?, :value 11})} From ea31ba766ac83a8dd45b296d4656ee440a3a330b Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:32:59 +0300 Subject: [PATCH 03/10] Fix example. Fixes #1187 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 052692847..6d4fc68de 100644 --- a/README.md +++ b/README.md @@ -915,7 +915,7 @@ Top-level humanized map-errors are under `:malli/error`: (m/explain {:password "secret" :password2 "faarao"}) (me/humanize)) -; {:malli/error ["passwords don't match"]} +; => ["passwords don't match"] ``` Errors can be targeted using `:error/path` property: From 4a84083d6817f1daa13c48b5e72d5394d5d4660e Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:50:03 +0300 Subject: [PATCH 04/10] Fix to match what Malli does --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 6d4fc68de..968b9e5e2 100644 --- a/README.md +++ b/README.md @@ -966,8 +966,7 @@ For closed schemas, key spelling can be checked with: :address {:streetz "Hämeenkatu 14"}}) (me/with-spell-checking) (me/humanize)) -;{:address {:street ["missing required key"] -; :streetz ["should be spelled :street"]} +;{:address {:streetz ["should be spelled :street"]} ; :name ["disallowed key"]} ``` From 11958f20ff0af9764a4b09f28a6696f9649baa66 Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:50:21 +0300 Subject: [PATCH 05/10] Fix example, the expected outputs were reversed --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 968b9e5e2..b8ea765a6 100644 --- a/README.md +++ b/README.md @@ -1818,9 +1818,9 @@ is equivalent to `[:map [:x [:or :string :int]]]`. {:registry registry})) (m/validate MergedCommon {:x "kikka"}) -; => true -(m/validate MergedCommon {:x 1}) ; => false +(m/validate MergedCommon {:x 1}) +; => true (m/validate UnionCommon {:x "kikka"}) ; => true (m/validate UnionCommon {:x 1}) From 292a384bf30d28ecb33b342bbc75e644716672b5 Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:50:45 +0300 Subject: [PATCH 06/10] Fix examples, malli generates keyword specs now --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8ea765a6..bb3edb991 100644 --- a/README.md +++ b/README.md @@ -2322,7 +2322,7 @@ Sample-data can be type-hinted with `::mp/hint`: [^{::mp/hint :tuple} [1 "kikka" true] ["2" "kukka" true]]) -; [:tuple :some string? boolean?] +; [:tuple :some :string :boolean] ``` ### value decoding in inferring @@ -2333,7 +2333,7 @@ By default, no decoding is applied for (leaf) values: (mp/provide [{:id "caa71a26-5fe1-11ec-bf63-0242ac130002"} {:id "8aadbf5e-5fe3-11ec-bf63-0242ac130002"}]) -; => [:map [:id string?]] +; => [:map [:id :string]] ``` Adding custom decoding via `::mp/value-decoders` option: From a0bb9f6f8e7b33d218aab51133c85ba1e30846ed Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:51:22 +0300 Subject: [PATCH 07/10] Fix example, add missing bracket --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb3edb991..24f4abf2d 100644 --- a/README.md +++ b/README.md @@ -2346,7 +2346,7 @@ Adding custom decoding via `::mp/value-decoders` option: :time "2022-01-01T00:00:00Z"}] {::mp/value-decoders {:string {:uuid mt/-string->uuid 'inst? mt/-string->date}}}) -; => [:map [:id :uuid] [:time inst?] +; => [:map [:id :uuid] [:time inst?]] ``` ## Destructuring From 330fb9c4086f60e2e20cb73e9f15698e8d2db3c0 Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:54:18 +0300 Subject: [PATCH 08/10] Fix example This behaviour changed in https://github.com/metosin/malli/pull/1021 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 24f4abf2d..2abcc59b7 100644 --- a/README.md +++ b/README.md @@ -2427,7 +2427,7 @@ A more complete example: ; [:cat [:= :h] [:maybe [:cat ; [:? :any] ; [:* :any]]]] -; [:cat :any :any]]]]]] +; [:cat [:not [:enum :d :e :demo/f :demo/g :h]] :any]]]]]] ``` ## Parsing values From 23227d682a4c2f41cf66116373d4bd837400c93b Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:54:49 +0300 Subject: [PATCH 09/10] Fix example to match naming in Malli --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2abcc59b7..e522674fa 100644 --- a/README.md +++ b/README.md @@ -2522,7 +2522,7 @@ The inverse of parsing, using `m/unparse` and `m/unparser`: ```clojure (m/unparse [:orn [:name :string] [:id :int]] - (m/tagged :name "x")) + (m/tag :name "x")) ; => "x" (m/unparse [:* [:catn [:name :string] [:id :int]]] From 1040accad3c65a81ca56aaab5b248af189bb8455 Mon Sep 17 00:00:00 2001 From: Matti Uusitalo Date: Thu, 8 May 2025 08:55:15 +0300 Subject: [PATCH 10/10] Fix example --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e522674fa..093c02bd0 100644 --- a/README.md +++ b/README.md @@ -3323,6 +3323,8 @@ As the namespace suggests, it's experimental, built for [reitit](https://github. ; [:min-max [:int {:min 0, :max 10}]] ; [:tuples [:vector [:tuple int? string?]]] ; [:optional {:optional true} [:maybe :boolean]] +; [:set-of-maps [:set [:map [:e int?] [:f string?]]]] +; [:map-of-int [:map-of int? [:map [:s string?]]]]]]] ``` Options can be used by binding a dynamic `l/*options*` Var: