Skip to content

Commit 89b1074

Browse files
committed
Merge branch 'master' of github.com:metosin/compojure-api
2 parents 552315c + 0b651c1 commit 89b1074

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/compojure/api/swagger.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
:spec \"/swagger.json\"
9595
:options {:ui {:jsonEditor true}
9696
:spec {}}
97-
:data {:info {:version \"1.0.0\"
97+
:data {:basePath \"/app\"
98+
:info {:version \"1.0.0\"
9899
:title \"Sausages\"
99100
:description \"Sausage description\"
100101
:termsOfService \"http://helloreverb.com/terms/\"
@@ -109,7 +110,7 @@
109110
(if options
110111
(let [{:keys [ui spec data] {ui-options :ui spec-options :spec} :options} (merge swagger-defaults options)]
111112
(c/routes
112-
(if ui (apply swagger-ui ui (mapcat identity (merge ui-options (if spec {:swagger-docs spec})))))
113+
(if ui (apply swagger-ui ui (mapcat identity (merge (if spec {:swagger-docs (apply str (remove clojure.string/blank? [(:basePath data) spec]))}) ui-options))))
113114
(if spec (apply swagger-docs spec (mapcat identity data))))))))
114115

115116
(defn validate

test/compojure/api/swagger_test.clj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,18 @@
170170
:path-params [foo :- String]
171171
identity))
172172
=> {"/:foo.json" {:get {:parameters {:path {:foo String}}}}})
173+
174+
(facts
175+
(tabular
176+
(fact "swagger-routes basePath can be changed"
177+
(let [app (api (swagger-routes ?given-options))]
178+
(->
179+
(get* app "/swagger.json")
180+
(nth 1)
181+
:basePath)
182+
=> ?expected-base-path
183+
(nth (raw-get* app "/conf.js") 1) => (str "window.API_CONF = {\"url\":\"" ?expected-swagger-docs-path "\"};")))
184+
?given-options ?expected-swagger-docs-path ?expected-base-path
185+
{} "/swagger.json" "/"
186+
{:data {:basePath "/app"}} "/app/swagger.json" "/app"
187+
{:data {:basePath "/app"} :options {:ui {:swagger-docs "/imaginary.json"}}} "/imaginary.json" "/app"))

0 commit comments

Comments
 (0)