Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.16.0 #1046

Merged
merged 7 commits into from
Apr 20, 2024
Merged

0.16.0 #1046

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
# Supported Java versions: LTS releases and latest
jdk: [8, 11, 17, 21]
jdk: [11, 17, 21]
clojure: [11]

name: Clojure ${{ matrix.clojure }} (Java ${{ matrix.jdk }})
Expand All @@ -26,7 +26,7 @@ jobs:
with:
distribution: zulu
java-version: ${{ matrix.jdk }}
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.m2/repository
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
with:
distribution: zulu
java-version: 11
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.m2/repository
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
with:
distribution: zulu
java-version: 11
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: |
~/.m2/repository
Expand Down
24 changes: 18 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino

Malli is in well matured [alpha](README.md#alpha).

## 0.16.0 (2024-04-20)

* **BREAKING**: minimum Java-version is now Java11
* allow changing prefix of json-schema $refs via option `:malli.json-schema/definitions-path` [#1045](https://github.com/metosin/malli/pull/1045)
* Inline refs in non-`:body` swagger parameters [#1044](https://github.com/metosin/malli/pull/1044)
* Fix flaky test [#1040](https://github.com/metosin/malli/pull/1040)
* Utility to update entry properties: `mu/update-entry-properties` [#1037](https://github.com/metosin/malli/pull/1037)
* Fix actions cache [#1036](https://github.com/metosin/malli/pull/1036)
* Only humanize one of `:min` / `:max` when different [#1032](https://github.com/metosin/malli/pull/1032)
* Distinguish between symbols and strings in humanize [#1031](https://github.com/metosin/malli/pull/1031)
* Fix `:map-of` `:min` and unreachable generator, explain such-that failures [#1029](https://github.com/metosin/malli/pull/1029)

## 0.15.0 (2024-03-23)

* `:=>` takes optional 3rd child, the guard schema validating vector of arguments and return value `[args ret]`. See [Function Guards](docs/function-schemas.md#function-guards) for more details. Fixes [#764](https://github.com/metosin/malli/issues/764) and [#764](https://github.com/metosin/malli/issues/764).
Expand Down Expand Up @@ -561,14 +573,14 @@ No need to play with Compiler options or JVM properties to swap the default regi

;; look ma, just works
(mr/set-default-registry!
(mr/composite-registry
(m/default-schemas)
(mu/schemas)))
(mr/composite-registry
(m/default-schemas)
(mu/schemas)))

(mg/generate
[:merge
[:map [:x :int]]
[:map [:y :int]]])
[:merge
[:map [:x :int]]
[:map [:y :int]]])
; => {:x 0, :y 92}
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ So, we decided to spin out our own library, which would do all the things we fee

[![Clojars Project](http://clojars.org/metosin/malli/latest-version.svg)](http://clojars.org/metosin/malli)

Malli requires Clojure 1.11.
Malli requires Java 11 and Clojure 1.11.

## Quickstart

Expand Down
6 changes: 3 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mvxcvi/arrangement {:mvn/version "2.1.0"}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {com.gfredericks/test.chuck {:mvn/version "0.2.14"}
lambdaisland/kaocha {:mvn/version "1.87.1366"}
lambdaisland/kaocha {:mvn/version "1.88.1376"}
lambdaisland/kaocha-cljs {:mvn/version "1.5.154"}
org.babashka/sci {:mvn/version "0.8.41"}
lambdaisland/kaocha-junit-xml {:mvn/version "1.17.101"}
Expand All @@ -19,7 +19,7 @@
prismatic/schema {:mvn/version "1.4.1"}
minimallist/minimallist {:mvn/version "0.0.10"}
net.cgrand/seqexp {:mvn/version "0.6.2"}
djblue/portal {:mvn/version "0.53.0"}
djblue/portal {:mvn/version "0.55.1"}
meta-merge/meta-merge {:mvn/version "1.0.0"}
expound/expound {:mvn/version "0.9.0"}
lambdaisland/deep-diff {:mvn/version "0.0-47"}
Expand Down Expand Up @@ -49,7 +49,7 @@
org.clojure/tools.namespace #_:clj-kondo/ignore {:mvn/version "RELEASE"}}}

:shadow {:extra-paths ["app"]
:extra-deps {thheller/shadow-cljs {:mvn/version "2.28.2"}
:extra-deps {thheller/shadow-cljs {:mvn/version "2.28.3"}
binaryage/devtools {:mvn/version "1.0.7"}}}
:slow {:extra-deps {io.dominic/slow-namespace-clj
{:git/url "https://git.sr.ht/~severeoverfl0w/slow-namespace-clj"
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>metosin</groupId>
<artifactId>malli</artifactId>
<version>0.15.0</version>
<version>0.16.0</version>
<name>malli</name>
<licenses>
<license>
Expand All @@ -15,7 +15,7 @@
<url>https://github.com/metosin/malli</url>
<connection>scm:git:git://github.com/metosin/malli.git</connection>
<developerConnection>scm:git:ssh://[email protected]/metosin/malli.git</developerConnection>
<tag>0.15.0</tag>
<tag>0.16.0</tag>
</scm>
<dependencies>
<dependency>
Expand Down
8 changes: 4 additions & 4 deletions src/malli/clj_kondo.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@
{:op :rest :spec child}
:seqable))

(defmethod accept :+ [_ _ children options] (-seqable-or-rest children options))
(defmethod accept :* [_ _ children options] (-seqable-or-rest children options))
(defmethod accept :? [_ _ children options] (-seqable-or-rest children options))
(defmethod accept :repeat [_ _ children options] (-seqable-or-rest children options))
(defmethod accept :+ [_ _ children options] (-seqable-or-rest children options))
(defmethod accept :* [_ _ children options] (-seqable-or-rest children options))
(defmethod accept :? [_ _ children options] (-seqable-or-rest children options))
(defmethod accept :repeat [_ _ children options] (-seqable-or-rest children options))

(defmethod accept :cat [_ _ children _] children)
(defmethod accept :catn [_ _ children _] (mapv last children))
Expand Down
3 changes: 2 additions & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,8 @@

(defn -default-sci-options []
{:preset :termination-safe
:aliases {'str 'clojure.string}
:aliases {'str 'clojure.string
'm 'malli.core}
:namespaces {'malli.core {'properties properties
'type type
'children children
Expand Down
4 changes: 1 addition & 3 deletions src/malli/error.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
[malli.core :as m]
[malli.util :as mu]))

(defn- -pr-str [v]
#?(:clj (pr-str v)
:cljs (str v)))
(defn -pr-str [v] #?(:clj (pr-str v), :cljs (str v)))

(defn -pred-min-max-error-fn [{:keys [pred message]}]
(fn [{:keys [schema value]} _]
Expand Down
28 changes: 14 additions & 14 deletions src/malli/experimental/time.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"Periods are not comparable in the java Comparable sense, instead this performs simple units-by-units comparison.
So a period of 1 year will always compare greater than a period of 13 months and similar for days and months."
[^Period p1 ^Period p2]
(let [years1 #?(:clj (.getYears p1) :cljs (.years p1))
years2 #?(:clj (.getYears p2) :cljs (.years p2))
(let [years1 #?(:clj (.getYears p1) :cljs (.years p1))
years2 #?(:clj (.getYears p2) :cljs (.years p2))
months1 #?(:clj (.getMonths p1) :cljs (.months p1))
months2 #?(:clj (.getMonths p2) :cljs (.months p2))
days1 #?(:clj (.getDays p1) :cljs (.days p1))
days2 #?(:clj (.getDays p2) :cljs (.days p2))]
days1 #?(:clj (.getDays p1) :cljs (.days p1))
days2 #?(:clj (.getDays p2) :cljs (.days p2))]
(cond
(not (= years1 years2)) (- years1 years2)
(not (= months1 months2)) (- months1 months2)
Expand All @@ -52,8 +52,8 @@
(if (and (instance? Period min) (instance? Period max))
(fn [^Period x]
(and
(not (pos? (compare-periods x max)))
(not (pos? (compare-periods min x)))))
(not (pos? (compare-periods x max)))
(not (pos? (compare-periods min x)))))
(fn [x] (and (<= x max) (<= min x))))
min (fn [x]
(if (instance? Period min)
Expand All @@ -66,14 +66,14 @@

(defn -temporal-schema [{:keys [type class type-properties]}]
(m/-simple-schema
(cond->
{:type type
:pred (fn pred [x]
#?(:clj (.isInstance ^Class class x)
:cljs (instance? class x)))
:property-pred (-min-max-pred nil)}
type-properties
(assoc :type-properties type-properties))))
(cond->
{:type type
:pred (fn pred [x]
#?(:clj (.isInstance ^Class class x)
:cljs (instance? class x)))
:property-pred (-min-max-pred nil)}
type-properties
(assoc :type-properties type-properties))))

#?(:cljs
(defn createTemporalQuery [f]
Expand Down
24 changes: 12 additions & 12 deletions src/malli/experimental/time/generator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,22 @@
floor-min (fn [v] (if (nil? v) min-int (max min-int v)))
{^Period mn :min ^Period mx :max ^Period gen-min :gen/min ^Period gen-max :gen/max}
(merge
(m/type-properties schema options)
(m/properties schema options))
(m/type-properties schema options)
(m/properties schema options))
_ (when (and mn gen-min (not (pos? (time/compare-periods gen-min min))))
(m/-fail! ::mg/invalid-property {:key :gen/min, :value gen-min, :min min}))
_ (when (and mx gen-max (not (pos? (time/compare-periods max gen-max))))
_ (when (and mx gen-max (not (pos? (time/compare-periods max gen-max))))
(m/-fail! ::mg/invalid-property {:key :gen/max, :value gen-min, :max min}))
mn (or mn gen-min)
mx (or mx gen-max)
min-years (when mn (zero->nil (.getYears mn))), max-years (when mx (zero->nil (.getYears mx)))
min-years (when mn (zero->nil (.getYears mn))), max-years (when mx (zero->nil (.getYears mx)))
min-months (when mn (zero->nil (.getMonths mn))), max-months (when mx (zero->nil (.getMonths mx)))
min-days (when mn (zero->nil (.getDays mn))), max-days (when mx (zero->nil (.getDays mx)))]
min-days (when mn (zero->nil (.getDays mn))), max-days (when mx (zero->nil (.getDays mx)))]
(->>
(gen/tuple
;; Period constructor only accepts java type `int` not `long`, clamp the values
(gen/large-integer* {:min (floor-min min-years) :max (ceil-max max-years)})
(gen/large-integer* {:min (floor-min min-months) :max (ceil-max max-months)})
(gen/large-integer* {:min (floor-min min-days) :max (ceil-max max-days)}))
(gen/fmap (fn [[years months days]]
(. Period of years months days))))))
(gen/tuple
;; Period constructor only accepts java type `int` not `long`, clamp the values
(gen/large-integer* {:min (floor-min min-years) :max (ceil-max max-years)})
(gen/large-integer* {:min (floor-min min-months) :max (ceil-max max-months)})
(gen/large-integer* {:min (floor-min min-days) :max (ceil-max max-days)}))
(gen/fmap (fn [[years months days]]
(. Period of years months days))))))
14 changes: 7 additions & 7 deletions src/malli/transform.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@
strip-map-of (fn [stage]
{:compile (fn [schema options]
(let [entry-schema (m/into-schema :tuple nil (m/children schema) options)
valid? (m/validator entry-schema options)]
valid? (m/validator entry-schema options)]
{stage (fn [x]
(reduce (fn [acc entry]
(if (valid? entry)
(apply assoc acc entry)
acc)) (empty x) x))}))})]
(reduce (fn [acc entry]
(if (valid? entry)
(apply assoc acc entry)
acc)) (empty x) x))}))})]
(transformer
{:decoders {:map strip-map, :map-of (strip-map-of :leave)}
:encoders {:map strip-map, :map-of (strip-map-of :enter)}}))))
{:decoders {:map strip-map, :map-of (strip-map-of :leave)}
:encoders {:map strip-map, :map-of (strip-map-of :enter)}}))))

(defn key-transformer [{:keys [decode encode types] :or {types #{:map}}}]
(let [transform (fn [f stage] (when f {stage (-transform-map-keys f)}))]
Expand Down
18 changes: 9 additions & 9 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2426,13 +2426,13 @@
(is (nil? (explain-times function-schema-validation-times schema2 (fn [x y] (unchecked-add x y)))))

(testing "exception in execution causes single error to root schema path"
(is (results= {:schema [:=> [:cat int? int?] int?]
:value single-arity
:errors [{:path []
:in []
:schema [:=> [:cat int? int?] int?]
:value single-arity}]}
(m/explain schema2 single-arity))))
(is (results= {:schema [:=> [:cat int? int?] int?]
:value single-arity
:errors [{:path []
:in []
:schema [:=> [:cat int? int?] int?]
:value single-arity}]}
(m/explain schema2 single-arity))))

(testing "error in output adds error to child in path 1"
(let [f (fn [x y] (str x y))]
Expand Down Expand Up @@ -2527,15 +2527,15 @@
(testing "guards"
(let [guard (fn [[[x y] z]] (= (str x y) z))
schema (m/schema
[:=> [:cat :int :int] string? [:fn guard]]
[:=> [:cat :int :int] :string [:fn guard]]
{::m/function-checker mg/function-checker})
valid (fn [x y] (str x y))
invalid (fn [x y] (str x "-" y))]

(is (= {:type :=>,
:input {:type :cat
:children [{:type :int} {:type :int}]},
:output {:type 'string?},
:output {:type :string},
:guard {:type :fn
:value guard}}
(m/ast schema)))
Expand Down