Skip to content

Commit 000a7f4

Browse files
committed
replace static-context macro without compojure impl details
1 parent 0793f40 commit 000a7f4

3 files changed

Lines changed: 17 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ See also: [compojure-api 1.1.x changelog](./CHANGELOG-1.1.x.md)
88
* saves 1 evaluation per schema, per request, for dynamic contexts
99
* Fix: Merge `:{form,multipart}-params` `:info :public :parameters :formData` field at runtime
1010
* Add `:outer-lets` field to `restructure-param` result which wraps entire resulting form
11+
* Remove `static-context` macro and replace with equivalent expansion without relying on compojure internals.
1112

1213
## 2.0.0-alpha32 (2024-03-20)
1314

src/compojure/api/meta.clj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,6 @@
648648
`(do ~@body)
649649
(reverse (partition 2 bindings))))
650650

651-
(defmacro static-context
652-
[path route]
653-
`(compojure.api.compojure-compat/make-context
654-
~(#'compojure.core/context-route path)
655-
(let [r# ~route]
656-
(fn [_#] r#))))
657-
658651
(defn routing [handlers]
659652
(if-let [handlers (seq (keep identity (flatten handlers)))]
660653
(apply compojure.core/routes handlers)
@@ -1080,7 +1073,8 @@
10801073
form)
10811074
form (if (seq middleware) `((mw/compose-middleware ~middleware) ~form) form)
10821075
form (if static-context?
1083-
`(static-context ~path ~form)
1076+
`(let [form# ~form]
1077+
(compojure.core/context ~path ~arg-with-request form#))
10841078
`(compojure.core/context ~path ~arg-with-request ~form))
10851079

10861080
;; create and apply a separate lookup-function to find the inner routes

test/compojure/api/meta_test.clj

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns compojure.api.meta-test
22
(:require [compojure.api.sweet :as sweet :refer :all]
3-
[compojure.api.meta :as meta :refer [merge-parameters static-context routing]]
3+
[compojure.api.meta :as meta :refer [merge-parameters routing]]
44
[compojure.api.common :refer [merge-vector]]
55
[compojure.api.compojure-compat :refer [make-context]]
66
[clojure.data :as data]
@@ -258,8 +258,11 @@
258258
:method nil,
259259
:info (merge-parameters {:static-context? true}),
260260
:handler
261-
(static-context "/a"
262-
(routing [(~'POST "/ping" [])]))})))
261+
(let [?form (routing [(~'POST "/ping" [])])]
262+
(cc/context
263+
"/a"
264+
[:as +compojure-api-request+]
265+
?form))})))
263266
(testing "dynamic context"
264267
(is-expands (context "/a" [] :dynamic true (POST "/ping" []))
265268
`(map->Route
@@ -277,18 +280,7 @@
277280
:handler
278281
(cc/context "/a"
279282
[:as +compojure-api-request+]
280-
(routing [(~'POST "/ping" [])]))})))
281-
(testing "static-context"
282-
(is-expands (static-context "/a"
283-
(routing [(POST "/ping" [])]))
284-
`(make-context
285-
{:__record__ "clout.core.CompiledRoute",
286-
:source "/a:__path-info",
287-
:re #"/a(|/.*)",
288-
:keys [:__path-info],
289-
:absolute? false}
290-
(let [?r ~'(routing [(POST "/ping" [])])]
291-
(fn [?_] ?r))))))
283+
(routing [(~'POST "/ping" [])]))}))))
292284

293285
(deftest is-thrown-with-msg?-test
294286
(is-thrown-with-msg? Exception #"message" (throw (Exception. "message")))
@@ -2145,3 +2137,10 @@
21452137
(is (= {:field 1 :default 1 :extra-keys 1 :extra-vals 1 :default-never 1} @times))
21462138
(dorun (repeatedly 10 exercise))
21472139
(is (= {:field 1 :default 1 :extra-keys 1 :extra-vals 1 :default-never 11} @times)))))
2140+
2141+
#_
2142+
(deftest push-context-parameters-into-endpoints-test
2143+
(macroexpand-2
2144+
`(context "/foo" []
2145+
:dynamic true
2146+
)))

0 commit comments

Comments
 (0)