mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 16:31:11 +00:00
Merge pull request #174 from nenadalm/async_ring
Support swagger with async ring
This commit is contained in:
commit
c3af856893
1 changed files with 29 additions and 23 deletions
|
|
@ -73,7 +73,8 @@
|
|||
(defn create-swagger-handler []
|
||||
"Create a ring handler to emit swagger spec. Collects all routes from router which have
|
||||
an intersecting `[:swagger :id]` and which are not marked with `:no-doc` route data."
|
||||
(fn [{:keys [::r/router ::r/match :request-method]}]
|
||||
(fn create-swagger
|
||||
([{:keys [::r/router ::r/match :request-method]}]
|
||||
(let [{:keys [id] :or {id ::default} :as swagger} (-> match :result request-method :data :swagger)
|
||||
->set (fn [x] (if (or (set? x) (sequential? x)) (set x) (conj #{} x)))
|
||||
ids (->set id)
|
||||
|
|
@ -101,4 +102,9 @@
|
|||
[(path->template p) endpoint]))]
|
||||
(let [paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) (into {}))]
|
||||
{:status 200
|
||||
:body (meta-merge swagger {:paths paths})}))))
|
||||
:body (meta-merge swagger {:paths paths})})))
|
||||
([req res raise]
|
||||
(try
|
||||
(res (create-swagger req))
|
||||
(catch #?(:clj Exception :cljs :default) e
|
||||
(raise e))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue