mirror of
https://github.com/metosin/reitit.git
synced 2025-12-24 02:48:25 +00:00
swagger-ui path work, wip
This commit is contained in:
parent
7a544cd52d
commit
fa078470c5
2 changed files with 17 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue