Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Apr 22, 2024
1 parent 1f04126 commit 62a12a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -667,17 +667,21 @@
'compojure.api.sweet/resource
'compojure.api.resource/resource))

(defn- static-endpoint? [&env body]
(and (seq? body)
(def routes-vars #{'compojure.api.sweet/routes
'compojure.api.resource/routes})

(declare static-body?)

(defn- static-endpoint? [&env form]
(and (seq? form)
(boolean
(let [sym (first body)]
(let [sym (first form)]
(when (symbol? sym)
(when-some [v (resolve &env sym)]
(when (var? v)
(endpoint-vars
(symbol v)))))))))

(declare static-body?)
(or (endpoint-vars (symbol v))
(and (routes-vars (symbol v))
(static-body? &env (next form)))))))))))

(def context-vars (into #{}
(mapcat (fn [n]
Expand Down Expand Up @@ -789,6 +793,8 @@
(defn- static-body? [&env body]
(every? #(or (static-endpoint? &env %)
(contains? &env %) ;;local
(when (symbol? %)
(var? (resolve &env %))) ;;var deref
((some-fn keyword? number? boolean?) %)
(static-cond? &env %)
(static-context? &env %)
Expand Down
5 changes: 5 additions & 0 deletions test/compojure/api/swagger_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

(fact "all compojure.api.core macros are interpreted"
(let [app (context "/a" []
:static true ;;FIXME nested static/dynamic?
(routes
(context "/b" []
:dynamic true
(let-routes []
(GET "/c" [] identity)
(POST "/d" [] identity)
Expand All @@ -26,6 +28,7 @@
(GET "/k/:l/m/:n" [] identity))))]

(extract-paths app)
#_#_
=> {"/a/b/c" {:get {}}
"/a/b/d" {:post {}}
"/a/b/e" {:put {}}
Expand All @@ -47,12 +50,14 @@
(fact "route-macros are expanded"
(extract-paths
(context "/api" []
:static true
(optional-routes true (GET "/true" [] identity))
(optional-routes false (PUT "/false" [] identity)))) => {"/api/true" {:get {}}})

(fact "endpoint-macros are expanded"
(extract-paths
(context "/api" []
:static true
(GET+ "/true" [] identity))) => {"/api/xxx/true" {:get {}}})

(fact "Vanilla Compojure defroutes are NOT followed"
Expand Down

0 comments on commit 62a12a3

Please sign in to comment.