File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 [compojure.api.routes :as routes]
66 [compojure.core :refer :all ]
77 [potemkin :refer [import-vars]]
8- [ring.swagger.middleware :as rsm]
98 [ring.swagger.common :refer [extract-parameters]]
109 [clojure.walk :as walk]
1110 backtick))
1615 lookup table via wrap-options. Returned handler retains the original
1716 meta-data."
1817 [handler options]
19- (let [{:keys [routes lookup] :as meta}
20- (-> handler meta (update-in [:routes ] routes/route-vector-to-route-map))]
18+ (let [meta (-> handler meta (assoc :options options))]
2119 (-> handler
22- (rsm/wrap-swagger-data routes)
2320 (mw/api-middleware options)
24- (mw/wrap-options { :lookup lookup} )
25- (with-meta ( assoc meta :options options) ))))
21+ (mw/wrap-options ( select-keys meta [ :routes : lookup]) )
22+ (with-meta meta))))
2623
2724(defmacro api
2825 " Returns a ring handler wrapped in compojure.api.middleware/api-middlware.
Original file line number Diff line number Diff line change 305305 :name ::swagger
306306 (let [runtime-info# (rsm/get-swagger-data request#)
307307 base-path# {:basePath (base-path request#)}
308- options# (:ring-swagger (mw/get-options request#))]
308+ options# (:ring-swagger (mw/get-options request#))
309+ routes# (:routes (mw/get-options request#))
310+ paths# (routes/route-vector-to-route-map routes#)]
309311 (ok
310312 (let [swagger# (merge runtime-info#
313+ paths#
311314 base-path#
312315 ~extra-info)
313316 result# (swagger2/swagger-json swagger# options#)]
340343 endpoint is requested. Returns either the (valid) api or throws an
341344 exception."
342345 [api]
343- (let [{:keys [routes options]} (meta api)]
346+ (let [{:keys [routes options]} (meta api)
347+ routes (routes/route-vector-to-route-map routes)]
344348 (assert (not (nil? routes)) " Api did not contain route definitions." )
345349 (when (swagger-api? api)
346350
Original file line number Diff line number Diff line change 2626 (->> app
2727 meta
2828 :routes
29- :paths
30- keys) => [" /a/1"
31- " /a/2"
32- " /a/3"
33- " /a/b/4"
34- " /a/b/5"
35- " /a/c/6"
36- " /a/c/7"
37- " /a/c/8"
38- " /a/c/9"
39- " /a/c/10" ])))
29+ (map first)) => [" /a/1"
30+ " /a/2"
31+ " /a/3"
32+ " /a/b/4"
33+ " /a/b/5"
34+ " /a/c/6"
35+ " /a/c/7"
36+ " /a/c/8"
37+ " /a/c/9"
38+ " /a/c/10" ])))
Original file line number Diff line number Diff line change 55 [ring.mock.request :refer :all ]
66 [schema.core :as s]
77 [clojure.java.io :as io]
8- [scjsv.core :as scjsv]))
8+ [scjsv.core :as scjsv]
9+ [compojure.api.routes :as routes]))
910
1011(def validate
1112 (scjsv/validator (slurp (io/resource " ring/swagger/v2.0_schema.json" ))))
7172(facts " api documentation"
7273 (fact " details are generated"
7374
74- (-> app meta :routes )
75+ (-> app meta :routes routes/route-vector-to-route-map )
7576
7677 => {:paths {" /ping" {:get {}}
7778 " /api/ping" {:get {}}
You can’t perform that action at this time.
0 commit comments