mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Merge pull request #446 from zelark/update-handler
Update create-swagger-ui-handler
This commit is contained in:
commit
fb771a33bd
1 changed files with 10 additions and 16 deletions
|
|
@ -14,32 +14,26 @@
|
||||||
| :path | optional path to mount the handler to. Works only if mounted outside of a router.
|
| :path | optional path to mount the handler to. Works only if mounted outside of a router.
|
||||||
| :config | parameters passed to swaggger-ui as-is.
|
| :config | parameters passed to swaggger-ui as-is.
|
||||||
|
|
||||||
See https://github.com/swagger-api/swagger-ui/tree/2.x#parameters
|
See https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
|
||||||
for all available :config options
|
for all available :config options.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
```
|
||||||
|
(swagger-ui/create-swagger-ui-handler)
|
||||||
|
|
||||||
;; with defaults
|
|
||||||
(create-swagger-ui-handler)
|
|
||||||
|
|
||||||
;; with path and url set, swagger validator disabled, jsonEditor enabled
|
|
||||||
(swagger-ui/create-swagger-ui-handler
|
(swagger-ui/create-swagger-ui-handler
|
||||||
{:path \"/\"
|
{:path \"/swagger-ui\"
|
||||||
:url \"/api/swagger.json\"
|
:url \"/api/swagger.json\"
|
||||||
:config {:validatorUrl nil
|
:config {:validatorUrl nil}})
|
||||||
:jsonEditor true})"
|
```"
|
||||||
([]
|
([]
|
||||||
(create-swagger-ui-handler nil))
|
(create-swagger-ui-handler nil))
|
||||||
([options]
|
([options]
|
||||||
(let [config-json (fn [{:keys [url config]}] (j/write-value-as-string (merge config {:url url})))
|
(let [config-json (fn [{:keys [url config]}] (j/write-value-as-string (merge config {:url url})))
|
||||||
conf-js (fn [opts] (str "window.API_CONF = " (config-json opts) ";"))
|
|
||||||
options (as-> options $
|
options (as-> options $
|
||||||
(update $ :root (fnil identity "swagger-ui"))
|
(update $ :root (fnil identity "swagger-ui"))
|
||||||
(update $ :url (fnil identity "/swagger.json"))
|
(update $ :url (fnil identity "/swagger.json"))
|
||||||
(assoc $ :paths {"/conf.js" {:headers {"Content-Type" "application/javascript"}
|
(assoc $ :paths {"/config.json" {:headers {"Content-Type" "application/json"}
|
||||||
:status 200
|
|
||||||
:body (conf-js $)}
|
|
||||||
"/config.json" {:headers {"Content-Type" "application/json"}
|
|
||||||
:status 200
|
:status 200
|
||||||
:body (config-json $)}}))]
|
:body (config-json $)}}))]
|
||||||
(ring/routes
|
(ring/routes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue