mirror of
https://github.com/metosin/reitit.git
synced 2026-02-25 10:32:24 +00:00
Compare commits
No commits in common. "c3a152a44e7e46f93679b9d547099c9a2e6a33c0" and "9d88d92241d7ab9cfd0334d99e605814af8eea3c" have entirely different histories.
c3a152a44e
...
9d88d92241
4 changed files with 2 additions and 63 deletions
|
|
@ -16,7 +16,6 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino
|
||||||
|
|
||||||
* Improve & document how response schemas get picked in per-content-type coercion. See [docs](./doc/ring/coercion.md#per-content-type-coercion). [#745](https://github.com/metosin/reitit/issues/745).
|
* Improve & document how response schemas get picked in per-content-type coercion. See [docs](./doc/ring/coercion.md#per-content-type-coercion). [#745](https://github.com/metosin/reitit/issues/745).
|
||||||
* **BREAKING** Remove unused `reitit.dependency` ns. [#763](https://github.com/metosin/reitit/pull/763)
|
* **BREAKING** Remove unused `reitit.dependency` ns. [#763](https://github.com/metosin/reitit/pull/763)
|
||||||
* Support passing options to malli humanize. See [docs](./doc/coercion/malli_coercion.md). [#467](https://github.com/metosin/reitit/issues/467)
|
|
||||||
|
|
||||||
## 0.9.2 (2025-10-28)
|
## 0.9.2 (2025-10-28)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,29 +96,3 @@ Using `create` with options to create the coercion instead of `coercion`:
|
||||||
;; malli options
|
;; malli options
|
||||||
:options nil})
|
:options nil})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuring humanize error messages
|
|
||||||
|
|
||||||
Malli humanized error messages can be configured using `:options :errors`:
|
|
||||||
|
|
||||||
```clj
|
|
||||||
(reitit.coercion.malli/create
|
|
||||||
{:options
|
|
||||||
{:errors (assoc malli.error/default-errors
|
|
||||||
:malli.core/missing-key {:error/message {:en "MISSING"}})}})
|
|
||||||
```
|
|
||||||
|
|
||||||
See the malli docs for more info.
|
|
||||||
|
|
||||||
## Custom registry
|
|
||||||
|
|
||||||
Malli registry can be configured conveniently via `:options :registry`:
|
|
||||||
|
|
||||||
```clj
|
|
||||||
(require '[malli.core :as m])
|
|
||||||
|
|
||||||
(reitit.coercion.malli/create
|
|
||||||
{:options
|
|
||||||
{:registry {:registry (merge (m/default-schemas)
|
|
||||||
{:my-type :string})}}})
|
|
||||||
```
|
|
||||||
|
|
|
||||||
|
|
@ -188,8 +188,7 @@
|
||||||
(-open-model [_ schema] schema)
|
(-open-model [_ schema] schema)
|
||||||
(-encode-error [_ error]
|
(-encode-error [_ error]
|
||||||
(cond-> error
|
(cond-> error
|
||||||
(show? :humanized) (assoc :humanized (me/humanize error (cond-> {:wrap :message}
|
(show? :humanized) (assoc :humanized (me/humanize error {:wrap :message}))
|
||||||
options (merge options))))
|
|
||||||
(show? :schema) (update :schema edn/write-string opts)
|
(show? :schema) (update :schema edn/write-string opts)
|
||||||
(show? :errors) (-> (me/with-error-messages opts)
|
(show? :errors) (-> (me/with-error-messages opts)
|
||||||
(update :errors (partial map #(update % :schema edn/write-string opts))))
|
(update :errors (partial map #(update % :schema edn/write-string opts))))
|
||||||
|
|
|
||||||
|
|
@ -583,40 +583,7 @@
|
||||||
:request-method :get}))]
|
:request-method :get}))]
|
||||||
|
|
||||||
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call m/schema custom-meta-merge-checking-schema)))
|
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call m/schema custom-meta-merge-checking-schema)))
|
||||||
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call identity custom-meta-merge-checking-parameters)))))
|
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call identity custom-meta-merge-checking-parameters)))))))
|
||||||
|
|
||||||
(testing "malli options"
|
|
||||||
(let [->app (fn [options]
|
|
||||||
(ring/ring-handler
|
|
||||||
(ring/router
|
|
||||||
["/api" {:get {:parameters {:body [:map
|
|
||||||
[:i :int]
|
|
||||||
[:x :string]]}
|
|
||||||
:handler (fn [{{:keys [body]} :parameters}]
|
|
||||||
{:status 200 :body body})}}]
|
|
||||||
{:data {:middleware [rrc/coerce-exceptions-middleware
|
|
||||||
rrc/coerce-request-middleware
|
|
||||||
rrc/coerce-response-middleware]
|
|
||||||
:coercion (malli/create options)}})))
|
|
||||||
request {:uri "/api"
|
|
||||||
:request-method :get
|
|
||||||
:muuntaja/request {:format "application/json"}}]
|
|
||||||
(testing "humanize options"
|
|
||||||
(is (= {:i ["should be an integer"] :x ["missing required key"]}
|
|
||||||
(-> ((->app nil) (assoc request :body-params {:i "x"}))
|
|
||||||
:body
|
|
||||||
:humanized)))
|
|
||||||
(is (= {:i ["SHOULD INT"] :x ["MISSING"]}
|
|
||||||
(-> ((->app {:options {:errors {:int {:error/message {:en "SHOULD INT"}}
|
|
||||||
:malli.core/missing-key {:error/message {:en "MISSING"}}}}})
|
|
||||||
(assoc request :body-params {:i "x"}))
|
|
||||||
:body
|
|
||||||
:humanized))))
|
|
||||||
(testing "overriding registry"
|
|
||||||
(is (= {:body {:i "x" :x "x"} :status 200}
|
|
||||||
(-> ((->app {:options {:registry (merge (m/default-schemas)
|
|
||||||
{:int :string})}})
|
|
||||||
(assoc request :body-params {:i "x" :x "x"}))))))))))
|
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(deftest per-content-type-test
|
(deftest per-content-type-test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue