mirror of
https://github.com/metosin/reitit.git
synced 2026-01-24 07:09:01 +00:00
Merge pull request #774 from metosin/feat/753-doc-parameter-coercion
Some checks are pending
testsuite / Check cljdoc analysis (push) Waiting to run
testsuite / Clojure 11 (Java 11) (push) Waiting to run
testsuite / Clojure 11 (Java 17) (push) Waiting to run
testsuite / Clojure 11 (Java 21) (push) Waiting to run
testsuite / Clojure 11 (Java 25) (push) Waiting to run
testsuite / Clojure 12 (Java 11) (push) Waiting to run
testsuite / Clojure 12 (Java 17) (push) Waiting to run
testsuite / Clojure 12 (Java 21) (push) Waiting to run
testsuite / Clojure 12 (Java 25) (push) Waiting to run
testsuite / ClojureScript (push) Waiting to run
testsuite / Lint cljdoc.edn (push) Waiting to run
Some checks are pending
testsuite / Check cljdoc analysis (push) Waiting to run
testsuite / Clojure 11 (Java 11) (push) Waiting to run
testsuite / Clojure 11 (Java 17) (push) Waiting to run
testsuite / Clojure 11 (Java 21) (push) Waiting to run
testsuite / Clojure 11 (Java 25) (push) Waiting to run
testsuite / Clojure 12 (Java 11) (push) Waiting to run
testsuite / Clojure 12 (Java 17) (push) Waiting to run
testsuite / Clojure 12 (Java 21) (push) Waiting to run
testsuite / Clojure 12 (Java 25) (push) Waiting to run
testsuite / ClojureScript (push) Waiting to run
testsuite / Lint cljdoc.edn (push) Waiting to run
doc: document nuances of reitit.coercion/default-parameter-coercion
This commit is contained in:
commit
e3306e1876
1 changed files with 20 additions and 2 deletions
|
|
@ -63,8 +63,6 @@ Handlers can access the coerced parameters via the `:parameters` key in the requ
|
|||
{:status 200
|
||||
:body {:total total}}))})
|
||||
```
|
||||
|
||||
|
||||
### Nested parameter definitions
|
||||
|
||||
Parameters are accumulated recursively along the route tree, just like
|
||||
|
|
@ -94,6 +92,26 @@ handling for merging eg. malli `:map` schemas.
|
|||
; [:task-id :int]]}
|
||||
```
|
||||
|
||||
### Differences in behaviour for different parameters
|
||||
|
||||
All parameter coercions *except* `:body`:
|
||||
|
||||
1. Allow keys outside the schema (by opening up the schema using eg. `malli.util/open-schema`)
|
||||
2. Keywordize the keys (ie. header & query parameter names) of the input before coercing
|
||||
|
||||
In contrast, the `:body` coercion:
|
||||
|
||||
1. Uses the specified schema
|
||||
* depending on the coercion, it can be configured as open or closed, see specific coercion docs for details
|
||||
2. Does not keywordize the keys of the input before coercion
|
||||
* however, coercions like malli might do the keywordization when coercing json bodies, depending on configuration
|
||||
|
||||
This admittedly confusing behaviour is retained currently due to
|
||||
backwards compatibility reasons. It can be configured by passing
|
||||
option `:reitit.coercion/parameter-coercion` to `reitit.ring/router`
|
||||
or `reitit.coercion/compile-request-coercers`. See also:
|
||||
`reitit.coercion/default-parameter-coercion`.
|
||||
|
||||
## Coercion Middleware
|
||||
|
||||
Defining a coercion for a route data doesn't do anything, as it's just data. We have to attach some code to apply the actual coercion. We can use the middleware from `reitit.ring.coercion`:
|
||||
|
|
|
|||
Loading…
Reference in a new issue