From 62a12a35c8c08cb870d3323e872900a178620b27 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Mon, 22 Apr 2024 03:06:21 -0500 Subject: [PATCH] wip --- src/compojure/api/meta.clj | 20 +++++++++++++------- test/compojure/api/swagger_test.clj | 5 +++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/compojure/api/meta.clj b/src/compojure/api/meta.clj index e9d86452..961eab82 100644 --- a/src/compojure/api/meta.clj +++ b/src/compojure/api/meta.clj @@ -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] @@ -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 %) diff --git a/test/compojure/api/swagger_test.clj b/test/compojure/api/swagger_test.clj index 195fc36d..ca535a83 100644 --- a/test/compojure/api/swagger_test.clj +++ b/test/compojure/api/swagger_test.clj @@ -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) @@ -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 {}} @@ -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"