swagger-spec-handler => create-swagger-handler

This commit is contained in:
Tommi Reiman 2018-04-22 21:39:38 +03:00
parent 53bdc622ee
commit f66850dacb
3 changed files with 23 additions and 23 deletions

View file

@ -40,7 +40,7 @@
["/swagger.json"
{:get {:no-doc true
:swagger {:info {:title "my-api"}}
:handler swagger/swagger-spec-handler}}]
:handler (swagger/create-swagger-handler)}}]
["/spec" {:coercion spec/coercion}
["/plus"

View file

@ -65,24 +65,24 @@
{:name ::swagger
:spec ::spec})
(defn swagger-spec-handler
"Ring handler to emit swagger spec."
[{: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})
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 accept-route) (map transform-path) (into {}))]
{:status 200
:body (meta-merge swagger {:paths paths})}))))
(defn create-swagger-handler []
"Create a ring handler to emit swagger spec."
(fn [{: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})
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 accept-route) (map transform-path) (into {}))]
{:status 200
:body (meta-merge swagger {:paths paths})})))))

View file

@ -16,7 +16,7 @@
["/swagger.json"
{:get {:no-doc true
:swagger {:info {:title "my-api"}}
:handler swagger/swagger-spec-handler}}]
:handler (swagger/create-swagger-handler)}}]
["/spec" {:coercion spec/coercion}
["/plus"