diff --git a/src/compojure/api/swagger.clj b/src/compojure/api/swagger.clj index 431ea642..c9a4780a 100644 --- a/src/compojure/api/swagger.clj +++ b/src/compojure/api/swagger.clj @@ -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/\" @@ -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 diff --git a/test/compojure/api/swagger_test.clj b/test/compojure/api/swagger_test.clj index cc87b270..e47cfd63 100644 --- a/test/compojure/api/swagger_test.clj +++ b/test/compojure/api/swagger_test.clj @@ -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"))