mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11: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.
|
||||
| :config | parameters passed to swaggger-ui as-is.
|
||||
|
||||
See https://github.com/swagger-api/swagger-ui/tree/2.x#parameters
|
||||
for all available :config options
|
||||
See https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
|
||||
for all available :config options.
|
||||
|
||||
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
|
||||
{:path \"/\"
|
||||
{:path \"/swagger-ui\"
|
||||
:url \"/api/swagger.json\"
|
||||
:config {:validatorUrl nil
|
||||
:jsonEditor true})"
|
||||
:config {:validatorUrl nil}})
|
||||
```"
|
||||
([]
|
||||
(create-swagger-ui-handler nil))
|
||||
([options]
|
||||
(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 $
|
||||
(update $ :root (fnil identity "swagger-ui"))
|
||||
(update $ :url (fnil identity "/swagger.json"))
|
||||
(assoc $ :paths {"/conf.js" {:headers {"Content-Type" "application/javascript"}
|
||||
:status 200
|
||||
:body (conf-js $)}
|
||||
"/config.json" {:headers {"Content-Type" "application/json"}
|
||||
(assoc $ :paths {"/config.json" {:headers {"Content-Type" "application/json"}
|
||||
:status 200
|
||||
:body (config-json $)}}))]
|
||||
(ring/routes
|
||||
|
|
|
|||
Loading…
Reference in a new issue