Skip to content

Commit 6ed9f6f

Browse files
committed
Revert "undo rmf compat"
This reverts commit 4c5c260.
1 parent 4c5c260 commit 6ed9f6f

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

src/compojure/api/middleware.clj

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
;; Options
9090
;;
9191

92+
;; 1.1.x
93+
(defn get-options
94+
"Extracts compojure-api options from the request."
95+
[request]
96+
(::options request))
97+
9298
(defn wrap-inject-data
9399
"Injects data into the request."
94100
[handler data]
@@ -118,6 +124,13 @@
118124
(def no-response-coercion
119125
(constantly (dissoc default-coercion-matchers :response)))
120126

127+
(defn coercion-matchers [request]
128+
(let [options (get-options request)]
129+
(if (contains? options :coercion)
130+
(if-let [provider (:coercion options)]
131+
(provider request))
132+
default-coercion-matchers)))
133+
121134
;;
122135
;; Muuntaja
123136
;;
@@ -206,7 +219,8 @@
206219
;;
207220

208221
(def api-middleware-defaults
209-
{:formats ::default
222+
{::api-middleware-defaults true
223+
:formats ::default
210224
:exceptions {:handlers {:ring.util.http-response/response ex/http-response-handler
211225
::ex/request-validation ex/request-validation-handler
212226
::ex/request-parsing ex/request-parsing-handler
@@ -244,12 +258,21 @@
244258
245259
### Options
246260
261+
- **:formatter** either :ring-middleware-format or :muuntaja.
262+
During 2.x pre-releases, this will be a required key, unless
263+
:formats is provided, which is equivalent to setting to :muuntaja.
264+
Stable 2.x releases will default to :ring-middleware-format if
265+
not provided or :format is set, unless :formats is provided,
266+
which is equivalent to setting to :muuntaja.
267+
Stable 2.x will print a deprecation warning if implicitly
268+
or explicitly set to :ring-middleware-format.
269+
247270
- **:exceptions** for *compojure.api.middleware/wrap-exceptions* (nil to unmount it)
248271
- **:handlers** Map of error handlers for different exception types, type refers to `:type` key in ExceptionInfo data.
249272
250273
- **:formats** for Muuntaja middleware. Value can be a valid muuntaja options-map,
251274
a Muuntaja instance or nil (to unmount it). See
252-
https://github.com/metosin/muuntaja/wiki/Configuration for details.
275+
https://github.com/metosin/muuntaja/blob/master/doc/Configuration.md for details.
253276
254277
- **:middleware** vector of extra middleware to be applied last (just before the handler).
255278
@@ -266,9 +289,41 @@
266289
you might want to take look at using wrap-components
267290
middleware manually.). Defaults to nil (middleware not mounted)."
268291
([handler]
292+
(throw (ex-info (str "ERROR: Please set `:formatter :muuntaja` in the options map of `api-middleware.\n"
293+
"e.g., (api-middleware <handler> {:formatter :muuntaja})\n"
294+
"To prepare for backwards compatibility with compojure-api 1.x, the formatting library must be \n"
295+
"explicitly chosen if not configured by `:format` (ring-middleware-format) or\n"
296+
"`:formats` (muuntaja). Once 2.x is stable, the default will be `:formatter :ring-middleware-format`.")
297+
{}))
269298
(api-middleware handler api-middleware-defaults))
270299
([handler options]
271-
(let [options (api-middleware-options options)
300+
(when (and (::api-middleware-defaults options)
301+
(not (:formatter options))
302+
(not (System/getProperty "compojure.api.middleware.global-default-formatter")))
303+
(throw (ex-info (str "ERROR: Please set `:formatter :muuntaja` in the options map of `api-middleware.\n"
304+
"e.g., (api-middleware <handler> {:formatter :muuntaja})\n"
305+
"To prepare for backwards compatibility with compojure-api 1.x, the formatting library must be\n"
306+
"explicitly chosen if not configured by `:format` (ring-middleware-format) or\n"
307+
":formats (muuntaja). Once 2.x is stable, the default will be `:formatter :ring-middleware-format`.\n"
308+
"To globally override the default formatter, use -Dcompojure.api.middleware.global-default-formatter=:muuntaja")
309+
{})))
310+
(let [formatter (or (:formatter options)
311+
(when (or (contains? options :formats)
312+
(= (System/getProperty "compojure.api.middleware.global-default-formatter")
313+
":muuntaja"))
314+
:muuntaja)
315+
(throw (ex-info (str "ERROR: Please set `:formatter :muuntaja` in the options map of `api-middleware.\n"
316+
"e.g., (api-middleware <handler> {:formatter :muuntaja})\n"
317+
"To prepare for backwards compatibility with compojure-api 1.x, the formatting library must be\n"
318+
"explicitly chosen if not configured by `:format` (ring-middleware-format) or\n"
319+
":formats (muuntaja). Once 2.x is stable, the default will be `:formatter :ring-middleware-format`.\n"
320+
"To globally override the default formatter, use -Dcompojure.api.middleware.global-default-formatter=:muuntaja")
321+
{}))
322+
;; TODO 2.x stable
323+
:ring-middleware-format)
324+
_ (assert (= :muuntaja formatter)
325+
(str "Invalid :formatter: " (pr-str formatter) ". Must be :muuntaja."))
326+
options (api-middleware-options options)
272327
{:keys [exceptions components formats middleware ring-swagger coercion]} options
273328
muuntaja (create-muuntaja formats)]
274329

0 commit comments

Comments
 (0)