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