This commit is contained in:
Tommi Reiman 2018-03-18 11:32:17 +02:00
parent 8c39840eca
commit 5da599ac5b

View file

@ -70,19 +70,19 @@
[{:keys [::r/router ::r/match :request-method]}]
(let [{:keys [id] :as swagger} (-> match :result request-method :data :swagger)
swagger (set/rename-keys swagger {:id :x-id})
this-swagger? #(-> % second :swagger :id (= id))
transform-endpoint (fn [[method endpoint]]
(let [coercion (-> endpoint :data :coercion)]
(if (and endpoint (-> endpoint :data :no-doc not))
[method (meta-merge
(if coercion
(coercion/-get-apidocs coercion :swagger (-> endpoint :data)))
(-> endpoint :data (select-keys [:tags :summary :description]))
(-> endpoint :data :swagger (dissoc :id)))])))
accept-route #(-> % second :swagger :id (= id))
transform-endpoint (fn [[method {{:keys [coercion no-doc swagger] :as data} :data}]]
(if (and data (not no-doc))
[method
(meta-merge
(if coercion
(coercion/-get-apidocs coercion :swagger data))
(select-keys data [:tags :summary :description])
(dissoc swagger :id))]))
transform-path (fn [[p _ c]]
(if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))]
[p endpoint]))]
(if id
(let [paths (->> router (r/routes) (filter this-swagger?) (map transform-path) (into {}))]
(let [paths (->> router (r/routes) (filter accept-route) (map transform-path) (into {}))]
{:status 200
:body (meta-merge swagger {:paths paths})}))))