Skip to content

Commit

Permalink
Merge branch 'master' of github.com:metosin/compojure-api
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Feb 11, 2016
2 parents 552315c + 0b651c1 commit 89b1074
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compojure/api/swagger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
:spec \"/swagger.json\"
:options {:ui {:jsonEditor true}
:spec {}}
:data {:info {:version \"1.0.0\"
:data {:basePath \"/app\"
:info {:version \"1.0.0\"
:title \"Sausages\"
:description \"Sausage description\"
:termsOfService \"http://helloreverb.com/terms/\"
Expand All @@ -109,7 +110,7 @@
(if options
(let [{:keys [ui spec data] {ui-options :ui spec-options :spec} :options} (merge swagger-defaults options)]
(c/routes
(if ui (apply swagger-ui ui (mapcat identity (merge ui-options (if spec {:swagger-docs spec})))))
(if ui (apply swagger-ui ui (mapcat identity (merge (if spec {:swagger-docs (apply str (remove clojure.string/blank? [(:basePath data) spec]))}) ui-options))))
(if spec (apply swagger-docs spec (mapcat identity data))))))))

(defn validate
Expand Down
15 changes: 15 additions & 0 deletions test/compojure/api/swagger_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,18 @@
:path-params [foo :- String]
identity))
=> {"/:foo.json" {:get {:parameters {:path {:foo String}}}}})

(facts
(tabular
(fact "swagger-routes basePath can be changed"
(let [app (api (swagger-routes ?given-options))]
(->
(get* app "/swagger.json")
(nth 1)
:basePath)
=> ?expected-base-path
(nth (raw-get* app "/conf.js") 1) => (str "window.API_CONF = {\"url\":\"" ?expected-swagger-docs-path "\"};")))
?given-options ?expected-swagger-docs-path ?expected-base-path
{} "/swagger.json" "/"
{:data {:basePath "/app"}} "/app/swagger.json" "/app"
{:data {:basePath "/app"} :options {:ui {:swagger-docs "/imaginary.json"}}} "/imaginary.json" "/app"))

0 comments on commit 89b1074

Please sign in to comment.