|
6 | 6 | [ring.swagger.common :as rsc] |
7 | 7 | [ring.swagger.middleware :as rsm] |
8 | 8 | [ring.swagger.core :as swagger] |
9 | | - [ring.swagger.ui :as rsui] |
| 9 | + [ring.swagger.swagger-ui :as swagger-ui] |
10 | 10 | [ring.swagger.swagger2 :as swagger2] |
11 | 11 | [compojure.api.routes :as routes])) |
12 | 12 |
|
|
28 | 28 | (swagger2/transform-operations routes/non-nil-routes) |
29 | 29 | (swagger2/transform-operations routes/strip-no-doc-endpoints))) |
30 | 30 |
|
31 | | -(defn swagger-ui [& params] |
| 31 | +(defn swagger-ui [options] |
| 32 | + (assert (map? options) "Since 1.1.11, compojure.api.swagger/swagger-ui takes just one map as argument, with `:path` for the path.") |
32 | 33 | (c/undocumented |
33 | | - (apply rsui/swagger-ui params))) |
| 34 | + (swagger-ui/swagger-ui options))) |
34 | 35 |
|
35 | | -(defn swagger-docs [& body] |
36 | | - (let [[path body] (if (string? (first body)) |
37 | | - [(first body) (rest body)] |
38 | | - ["/swagger.json" body]) |
39 | | - [extra-info] (common/extract-parameters body false)] |
| 36 | +(defn swagger-docs [{:keys [path] :or {path "/swagger.json"} :as options}] |
| 37 | + (assert (map? options) "Since 1.1.11, compojure.api.swagger/swagger-docs takes just one map as argument, with `:path` for the path.") |
| 38 | + (let [extra-info (dissoc options :path)] |
40 | 39 | (c/GET path request |
41 | 40 | :no-doc true |
42 | 41 | :name ::swagger |
|
57 | 56 | (defn swagger-routes |
58 | 57 | "Returns routes for swagger-articats (ui & spec). Accepts an options map, with the |
59 | 58 | following options: |
60 | | -
|
61 | | - **:ui** Uri for the swagger-ui (defaults to \"/\"). |
| 59 | + **:ui** Path for the swagger-ui (defaults to \"/\"). |
62 | 60 | Setting the value to nil will cause the swagger-ui not to be mounted |
63 | | -
|
64 | | - **:spec** Uri for the swagger-spec (defaults to \"/swagger.json\") |
| 61 | + **:spec** Path for the swagger-spec (defaults to \"/swagger.json\") |
65 | 62 | Setting the value to nil will cause the swagger-ui not to be mounted |
66 | | -
|
67 | 63 | **:data** Swagger data in the Ring-Swagger format. |
68 | | -
|
69 | 64 | **:options** |
70 | 65 | **:ui** Options to configure the ui |
71 | 66 | **:spec** Options to configure the spec. Nada at the moment. |
72 | | -
|
73 | 67 | Example options: |
74 | | -
|
75 | 68 | {:ui \"/api-docs\" |
76 | 69 | :spec \"/swagger.json\" |
77 | 70 | :options {:ui {:jsonEditor true} |
|
89 | 82 | :tags [{:name \"sausages\", :description \"Sausage api-set\"}]}}" |
90 | 83 | ([] (swagger-routes {})) |
91 | 84 | ([options] |
92 | | - (let [{:keys [ui spec data] {ui-options :ui} :options} (merge swagger-defaults options)] |
| 85 | + (let [{:keys [ui spec data] {ui-options :ui} :options} (merge swagger-defaults options) |
| 86 | + path (apply str (remove clojure.string/blank? [(:basePath data) spec]))] |
93 | 87 | (if (or ui spec) |
94 | 88 | (c/routes |
95 | | - (if ui (apply swagger-ui ui (mapcat identity (merge (if spec {:swagger-docs (apply str (remove clojure.string/blank? [(:basePath data) spec]))}) ui-options)))) |
96 | | - (if spec (apply swagger-docs spec (mapcat identity data)))))))) |
| 89 | + (if ui (swagger-ui (merge (if spec {:swagger-docs path}) ui-options {:path ui}))) |
| 90 | + (if spec (swagger-docs (assoc data :path spec)))))))) |
0 commit comments