Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed May 13, 2024
1 parent 1cd7c7a commit feb24b7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@
(and (seq? body)
(boolean
(when-some [v (resolve-var &env (first body))]
(when (middleware-vars (symbol v))
(when (middleware-vars (var->sym v))
(let [[_ mid & body] body]
(and (static-form? &env mid)
(static-body? &env body))))))))
Expand Down
6 changes: 4 additions & 2 deletions src/compojure/api/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@

(defn- ring-middleware-format-api-middleware
[handler options]
(require 'ring.middleware.format-params
'ring.middleware.format-response)
(let [{:keys [exceptions format components]} options
{:keys [formats params-opts response-opts]} format]
(cond-> handler
Expand All @@ -329,12 +331,12 @@
(seq formats) (rsm/wrap-swagger-data {:produces (->mime-types (remove response-only-mimes formats))
:consumes (->mime-types formats)})
true (wrap-options (select-keys options [:ring-swagger :coercion]))
(seq formats) ((requiring-resolve 'ring.middleware.format-params/wrap-restful-params)
(seq formats) ((resolve 'ring.middleware.format-params/wrap-restful-params)
{:formats (remove response-only-mimes formats)
:handle-error handle-req-error
:format-options params-opts})
exceptions (wrap-exceptions exceptions)
(seq formats) ((requiring-resolve 'ring.middleware.format-response/wrap-restful-response)
(seq formats) ((resolve 'ring.middleware.format-response/wrap-restful-response)
{:formats formats
:predicate serializable?
:format-options response-opts})
Expand Down
87 changes: 42 additions & 45 deletions test/compojure/api/integration_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -553,90 +553,87 @@
:definitions {}
:paths {"/user" {:get {:responses {:default {:description ""}}}}}}))))

(fact "swagger-routes"
(testing "swagger-routes"

(fact "with defaults"
(testing "with defaults"
(let [app (api (swagger-routes))]

(fact "api-docs are mounted to /"
(testing "api-docs are mounted to /"
(let [[status body] (raw-get* app "/")]
status => 200
body => #"<title>Swagger UI</title>"))
(is (= 200 status))
(is (str/includes? body "<title>Swagger UI</title>"))))

(fact "spec is mounted to /swagger.json"
(testing "spec is mounted to /swagger.json"
(let [[status body] (get* app "/swagger.json")]
status => 200
body => (contains {:swagger "2.0"})))))
(is (= 200 status))
(is (= "2.0" (:swagger body)))))))

(fact "with partial overridden values"
(testing "with partial overridden values"
(let [app (api (swagger-routes {:ui "/api-docs"
:data {:info {:title "Kikka"}
:paths {"/ping" {:get {}}}}}))]

(fact "api-docs are mounted"
(testing "api-docs are mounted"
(let [[status body] (raw-get* app "/api-docs")]
status => 200
body => #"<title>Swagger UI</title>"))
(is (= 200 status))
(is (str/includes? body "<title>Swagger UI</title>"))))

(fact "spec is mounted to /swagger.json"
(testing "spec is mounted to /swagger.json"
(let [[status body] (get* app "/swagger.json")]
status => 200
body => (contains
{:swagger "2.0"
:info (contains
{:title "Kikka"})
:paths (contains
{(keyword "/ping") anything})}))))))
(is (= 200 status))
(is (= "2.0" (:swagger body)))
(is (= "Kikka" (-> body :info :title)))
(is (some? (-> body :paths (get (keyword "/ping"))))))))))

(fact "swagger via api-options"
(testing "swagger via api-options"

(fact "with defaults"
(testing "with defaults"
(let [app (api)]

(fact "api-docs are not mounted"
(testing "api-docs are not mounted"
(let [[status body] (raw-get* app "/")]
status => nil))
(is (nil? status))))

(fact "spec is not mounted"
(testing "spec is not mounted"
(let [[status body] (get* app "/swagger.json")]
status => nil))))
(is (nil? status))))))

(fact "with spec"
(testing "with spec"
(let [app (api {:swagger {:spec "/swagger.json"}})]

(fact "api-docs are not mounted"
(testing "api-docs are not mounted"
(let [[status body] (raw-get* app "/")]
status => nil))
(is (nil? status))))

(fact "spec is mounted to /swagger.json"
(testing "spec is mounted to /swagger.json"
(let [[status body] (get* app "/swagger.json")]
status => 200
body => (contains {:swagger "2.0"}))))))
(is (nil? status))
(is (= "2.0" (:swagger body))))))))

(fact "with ui"
(testing "with ui"
(let [app (api {:swagger {:ui "/api-docs"}})]

(fact "api-docs are mounted"
(testing "api-docs are mounted"
(let [[status body] (raw-get* app "/api-docs")]
status => 200
body => #"<title>Swagger UI</title>"))
(is-200-status status)
(is (str/includes? body "<title>Swagger UI</title>"))))

(fact "spec is not mounted"
(testing "spec is not mounted"
(let [[status body] (get* app "/swagger.json")]
status => nil))))
(is (nil? status))))))

(fact "with ui and spec"
(testing "with ui and spec"
(let [app (api {:swagger {:spec "/swagger.json", :ui "/api-docs"}})]

(fact "api-docs are mounted"
(testing "api-docs are mounted"
(let [[status body] (raw-get* app "/api-docs")]
status => 200
body => #"<title>Swagger UI</title>"))
(is-200-status status)
(is (str/includes? body "<title>Swagger UI</title>"))))

(fact "spec is mounted to /swagger.json"
(testing "spec is mounted to /swagger.json"
(let [[status body] (get* app "/swagger.json")]
status => 200
body => (contains {:swagger "2.0"}))))))
(is-200-status status)
(is (= "2.0" (:swagger body))))))))

(deftest muuntaja-swagger-docs-test
(let [app (api
Expand Down

0 comments on commit feb24b7

Please sign in to comment.