File tree Expand file tree Collapse file tree 4 files changed +22
-21
lines changed Expand file tree Collapse file tree 4 files changed +22
-21
lines changed Original file line number Diff line number Diff line change 5
5
[compojure.api.routes :as routes]
6
6
[compojure.core :refer :all ]
7
7
[potemkin :refer [import-vars]]
8
- [ring.swagger.middleware :as rsm]
9
8
[ring.swagger.common :refer [extract-parameters]]
10
9
[clojure.walk :as walk]
11
10
backtick))
16
15
lookup table via wrap-options. Returned handler retains the original
17
16
meta-data."
18
17
[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))]
21
19
(-> handler
22
- (rsm/wrap-swagger-data routes)
23
20
(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))))
26
23
27
24
(defmacro api
28
25
" Returns a ring handler wrapped in compojure.api.middleware/api-middlware.
Original file line number Diff line number Diff line change 305
305
:name ::swagger
306
306
(let [runtime-info# (rsm/get-swagger-data request#)
307
307
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#)]
309
311
(ok
310
312
(let [swagger# (merge runtime-info#
313
+ paths#
311
314
base-path#
312
315
~extra-info)
313
316
result# (swagger2/swagger-json swagger# options#)]
340
343
endpoint is requested. Returns either the (valid) api or throws an
341
344
exception."
342
345
[api]
343
- (let [{:keys [routes options]} (meta api)]
346
+ (let [{:keys [routes options]} (meta api)
347
+ routes (routes/route-vector-to-route-map routes)]
344
348
(assert (not (nil? routes)) " Api did not contain route definitions." )
345
349
(when (swagger-api? api)
346
350
Original file line number Diff line number Diff line change 26
26
(->> app
27
27
meta
28
28
: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 5
5
[ring.mock.request :refer :all ]
6
6
[schema.core :as s]
7
7
[clojure.java.io :as io]
8
- [scjsv.core :as scjsv]))
8
+ [scjsv.core :as scjsv]
9
+ [compojure.api.routes :as routes]))
9
10
10
11
(def validate
11
12
(scjsv/validator (slurp (io/resource " ring/swagger/v2.0_schema.json" ))))
71
72
(facts " api documentation"
72
73
(fact " details are generated"
73
74
74
- (-> app meta :routes )
75
+ (-> app meta :routes routes/route-vector-to-route-map )
75
76
76
77
=> {:paths {" /ping" {:get {}}
77
78
" /api/ping" {:get {}}
You can’t perform that action at this time.
0 commit comments