swagger-ui path work, wip

This commit is contained in:
Tommi Reiman 2018-06-04 11:33:51 +03:00
parent 7a544cd52d
commit fa078470c5
2 changed files with 17 additions and 15 deletions

View file

@ -96,24 +96,26 @@
(fn
([request] (handler request))
([request respond _] (respond (handler request)))))
trim-path (fn [& paths] (str/replace (apply str paths) "//" "/"))
resource-response (fn [path]
(if-let [response (or (paths path) (response/resource-response path options))]
(if-let [response (or (paths (trim-path "/" path)) (response/resource-response path options))]
(response/content-type response (mime-type/ext-mime-type path))))
path-or-index-response (fn [path]
path-or-index-response (fn [path uri]
(or (resource-response path)
(let [separator (if-not (str/ends-with? path "/") "/")]
(loop [[file & files] index-files]
(if file
(or (resource-response (str path separator file))
(recur files)))))))
(loop [[file & files] index-files]
(if file
(let [path (trim-path path file)]
(if (resource-response path)
{:status 302 :headers {"Location" (trim-path uri "/" path)}}
(recur files)))))))
handler (if path
(fn [request]
(let [uri (:uri request)]
(if-let [path (if (>= (count uri) path-size) (subs uri path-size))]
(path-or-index-response path))))
(path-or-index-response path uri))))
(fn [request]
(let [path (-> request :path-params parameter)]
(or (path-or-index-response path) {:status 404}))))]
(or (path-or-index-response path path) {:status 404}))))]
(create handler)))))
(defn ring-handler

View file

@ -42,11 +42,11 @@
(update $ :root (fnil identity "swagger-ui"))
(update $ :url (fnil identity "/swagger.json"))
(update $ :config #(->> % (map mixed-case-key) (into {})))
(assoc $ :paths {"conf.js" {:headers {"Content-Type" "application/javascript"}
:status 200
:body (conf-js $)}
"config.json" {:headers {"Content-Type" "application/json"}
:status 200
:body (config-json $)}}))]
(assoc $ :paths {"/conf.js" {:headers {"Content-Type" "application/javascript"}
:status 200
:body (conf-js $)}
"/config.json" {:headers {"Content-Type" "application/json"}
:status 200
:body (config-json $)}}))]
(ring/routes
(ring/create-resource-handler options))))))