From 94780b9e7a9211c909f2adb8753ca0347b17d920 Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Tue, 10 May 2016 00:02:18 +0300 Subject: [PATCH 1/5] Can't inject nil-handers --- src/kekkonen/core.clj | 3 ++- test/kekkonen/core_test.clj | 22 ++++++++++++++-------- test/kekkonen/midje.clj | 2 ++ test/kekkonen/ring_test.clj | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/kekkonen/core.clj b/src/kekkonen/core.clj index 58f3f06..289720e 100644 --- a/src/kekkonen/core.clj +++ b/src/kekkonen/core.clj @@ -594,6 +594,7 @@ :no-doc nil ;; TODO: should this be defined in kekkonen.ring? :responses nil}}) + (s/defn dispatcher :- Dispatcher "Creates a Dispatcher" [options :- Options] @@ -618,7 +619,7 @@ (s/defn inject "Injects handlers into an existing Dispatcher" - [dispatcher :- Dispatcher, handlers] + [dispatcher :- Dispatcher, handlers :- (s/constrained s/Any (complement nil?) 'not-nil)] (if handlers (let [handler (collect-and-enrich (merge dispatcher {:handlers handlers :type-resolver any-type-resolver}) true)] diff --git a/test/kekkonen/core_test.clj b/test/kekkonen/core_test.clj index 741c587..dc01ce9 100644 --- a/test/kekkonen/core_test.clj +++ b/test/kekkonen/core_test.clj @@ -950,14 +950,20 @@ (fact "going meta boing boing" (k/invoke d :api/names) => #{:dispatcher :handler :names}))) -(fact "handlers can be injected into existing dispatcher" - (let [d (-> (k/dispatcher {:handlers {:api (k/handler {:name :test} identity)}}) - (k/inject (k/handler {:name :ping} identity)))] - d => (contains - {:handlers - (just - {:api/test anything - :ping anything})}))) +(fact "injecting handlers" + + (fact "handlers can be injected" + (let [d (-> (k/dispatcher {:handlers {:api (k/handler {:name :test} identity)}}) + (k/inject (k/handler {:name :ping} identity)))] + d => (contains + {:handlers + (just + {:api/test anything + :ping anything})}))) + + (fact "injecting nil handlers fails" + (-> (k/dispatcher {:handlers {:api (k/handler {:name :test} identity)}}) + (k/inject nil)) => schema-error?)) (facts "coercion-matcher" (let [PositiveInt (s/both s/Int (s/pred pos? 'positive)) diff --git a/test/kekkonen/midje.clj b/test/kekkonen/midje.clj index 6c7e034..b3b9909 100644 --- a/test/kekkonen/midje.clj +++ b/test/kekkonen/midje.clj @@ -1,6 +1,7 @@ (ns kekkonen.midje (:require [midje.util.exceptions :as e] [kekkonen.core :as k] + [schema.core :as s] [cheshire.core :as c])) (defn throws? @@ -14,6 +15,7 @@ (not (nil? x)) (= mdata m)))))) +(def schema-error? (throws? {:type ::s/error})) (def missing-route? (throws? {:type ::k/dispatch})) (def input-coercion-error? (throws? {:type ::k/request})) (def output-coercion-error? (throws? {:type ::k/response})) diff --git a/test/kekkonen/ring_test.clj b/test/kekkonen/ring_test.clj index 81ad96f..4fa1b21 100644 --- a/test/kekkonen/ring_test.clj +++ b/test/kekkonen/ring_test.clj @@ -44,7 +44,7 @@ (fact "request can be read as-is" (let [request {:uri "/api/snoop" :request-method :post}] (app request) => (ok request))) - + (fact "handles request within context" (let [request {:uri "/somecontext/api/ping" :request-method :post :context "/somecontext"}] (app request) => "pong")))) From 22234077204eb603a5c8cdb0a34213cfa90c89ed Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Tue, 10 May 2016 00:32:05 +0300 Subject: [PATCH 2/5] Use compojure-api 1.0.0 format for swagger-opts * Fixes #22 --- CHANGES.md | 20 +++++++++++ README.md | 8 +++-- dev-src/example/api.clj | 2 +- dev-src/example/cqrs.clj | 4 ++- dev-src/example/github/github.clj | 4 +-- examples/component/src/sample/handler.clj | 4 +-- src/kekkonen/api.clj | 23 +++++++----- src/kekkonen/cqrs.clj | 2 +- src/kekkonen/http.clj | 2 +- src/kekkonen/ring.clj | 4 +-- src/kekkonen/swagger.clj | 43 ++++++++++++++--------- test/kekkonen/api_test.clj | 22 ++++++++++++ test/kekkonen/swagger_test.clj | 25 +++++++------ 13 files changed, 111 insertions(+), 52 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7fb4efb..5710d3a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,26 @@ * *BREAKING*: Removed type-level interceptors from ring-adapter. * Support for Context-based urls, thanks to [Wout Neirynck](https://github.com/wneirynck). +* *BREAKING*: top-level swagger options are now in align to the compojure-api: + * Fixes [#22](https://github.com/metosin/kekkonen/issues/22) + +### Old + +```clj +{:swagger {:info {:title "Kekkonen"}} + :swagger-ui {:jsonEdit true}}) +``` + +### New + +```clj +{:swagger + {:spec "/swagger.json" + :ui "/api-docs" + :options {:ui {:jsonEdit true} + :spec {:ignore-missing-mappings? false}} + :data {:info {:title "Kekkonen"}}}} +``` * updated dependencies: diff --git a/README.md b/README.md index fbba2cf..5187544 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Mostly written as [issues](https://github.com/metosin/kekkonen/issues). Biggest (success {:result (+ x y)})) (defnk ^:command inc! - [[:components counter]] + [counter] (success {:result (swap! counter inc)})) ;; @@ -146,10 +146,12 @@ Mostly written as [issues](https://github.com/metosin/kekkonen/issues). Biggest (def app (cqrs-api - {:swagger {:info {:title "Kekkonen example"}} + {:swagger {:ui "/api-docs" + :spec "/swagger.json" + :data {:info {:title "Kekkonen example"}}} :core {:handlers {:api {:pizza #'echo-pizza :example [#'ping #'inc! #'plus]}} - :context {:components {:counter (atom 0)}}}})) + :context {:counter (atom 0)}}})) ;; ;; Start it diff --git a/dev-src/example/api.clj b/dev-src/example/api.clj index 12344ae..5da05a8 100644 --- a/dev-src/example/api.clj +++ b/dev-src/example/api.clj @@ -41,7 +41,7 @@ (def app (cqrs-api - {:swagger {:info {:title "Kekkonen example"}} + {:swagger {:data {:info {:title "Kekkonen example"}}} :core {:handlers {:api {:pizza #'echo-pizza :sample [#'ping #'inc! #'plus]}} :context {:components {:counter (atom 0)}}}})) diff --git a/dev-src/example/cqrs.clj b/dev-src/example/cqrs.clj index 5546a6d..2430eba 100644 --- a/dev-src/example/cqrs.clj +++ b/dev-src/example/cqrs.clj @@ -105,7 +105,9 @@ (def app (cqrs-api - {:swagger {:info {:title "Kekkonen"}} + {:swagger {:spec "/swagger.json" + :ui "/api-docs" + :data {:info {:title "Kekkonen"}}} :core {:handlers {:api {:item [#'get-items #'add-item #'reset-items] :calculator [#'plus #'times #'increment] :security #'get-user diff --git a/dev-src/example/github/github.clj b/dev-src/example/github/github.clj index a66bee3..fc5216a 100644 --- a/dev-src/example/github/github.clj +++ b/dev-src/example/github/github.clj @@ -112,8 +112,8 @@ (def app (cqrs-api - {:swagger {:info {:title "Kekkonen" - :version "1.0"}} + {:swagger {:data {:info {:title "Kekkonen" + :version "1.0"}}} :core {:handlers {:api {:github [#'get-repository #'list-repositorys #'fork diff --git a/examples/component/src/sample/handler.clj b/examples/component/src/sample/handler.clj index 888881a..03391d8 100644 --- a/examples/component/src/sample/handler.clj +++ b/examples/component/src/sample/handler.clj @@ -38,8 +38,8 @@ (p/defnk create [[:state counter]] (cqrs-api - {:swagger {:info {:title "Kekkonen with Component" - :description "created with http://kekkonen.io"}} + {:swagger {:data {:info {:title "Kekkonen with Component" + :description "created with http://kekkonen.io"}}} :core {:handlers {:api {:pizza #'echo-pizza :math [#'inc! #'plus] :ping #'ping}} diff --git a/src/kekkonen/api.clj b/src/kekkonen/api.clj index cb7a29e..86857d7 100644 --- a/src/kekkonen/api.clj +++ b/src/kekkonen/api.clj @@ -11,8 +11,7 @@ (s/optional-key :api) {:handlers k/KeywordMap} (s/optional-key :ring) r/Options (s/optional-key :mw) k/KeywordMap - (s/optional-key :swagger) k/KeywordMap - (s/optional-key :swagger-ui) k/KeywordMap}) + (s/optional-key :swagger) ks/Options}) (s/def +default-options+ :- Options {:core (-> k/+default-options+ @@ -21,18 +20,24 @@ :api {:handlers r/+kekkonen-handlers+} :ring r/+default-options+ :mw mw/+default-options+ - :swagger {:info {:title "Kekkonen API"}} - :swagger-ui ks/+default-swagger-ui-options+}) + ;; TODO: don't bind swagger.json & swagger-ui by default? + :swagger {:spec "/swagger.json" + :ui "/" + :data {:info {:title "Kekkonen API" + :version "0.0.1"}}}}) (defn api [options] (s/with-fn-validation (let [options (s/validate Options (kc/deep-merge-map-like +default-options+ options)) - swagger (merge (:swagger options) (mw/api-info (:mw options))) - dispatcher (-> (k/dispatcher (:core options)) - (k/inject (-> options :api :handlers)) - (k/inject (ks/swagger-handler swagger options)))] + api-handlers (-> options :api :handlers) + swagger-data (merge (-> options :swagger :data) (mw/api-info (:mw options))) + swagger-options (-> options :swagger) + swagger-handler (ks/swagger-handler swagger-data swagger-options) + dispatcher (cond-> (k/dispatcher (:core options)) + api-handlers (k/inject api-handlers) + swagger-handler (k/inject swagger-handler))] (mw/wrap-api (r/routes [(r/ring-handler dispatcher (:ring options)) - (ks/swagger-ui (:swagger-ui options))]) + (ks/swagger-ui swagger-options)]) (:mw options))))) diff --git a/src/kekkonen/cqrs.clj b/src/kekkonen/cqrs.clj index e9d8b20..8fc6d3c 100644 --- a/src/kekkonen/cqrs.clj +++ b/src/kekkonen/cqrs.clj @@ -47,7 +47,7 @@ (ka/api (kc/deep-merge-map-like {:core {:type-resolver (k/type-resolver :command :query)} - :swagger {:info {:title "Kekkonen CQRS API"}} + :swagger {:data {:info {:title "Kekkonen CQRS API"}}} :ring {:types {:query {:methods #{:get} :parameters {[:data] [:request :query-params]}} :command {:methods #{:post} diff --git a/src/kekkonen/http.clj b/src/kekkonen/http.clj index 53030fb..40e9b75 100644 --- a/src/kekkonen/http.clj +++ b/src/kekkonen/http.clj @@ -9,7 +9,7 @@ (ka/api (kc/deep-merge-map-like {:core {:type-resolver (k/type-resolver :get :head :patch :delete :options :post :put :any)} - :swagger {:info {:title "Kekkonen HTTP API"}} + :swagger {:data {:info {:title "Kekkonen HTTP API"}}} :ring {:types {:get {:methods #{:get}} :head {:methods #{:head}} :patch {:methods #{:patch}} diff --git a/src/kekkonen/ring.clj b/src/kekkonen/ring.clj index c5acc20..4d8fed3 100644 --- a/src/kekkonen/ring.clj +++ b/src/kekkonen/ring.clj @@ -167,8 +167,8 @@ (s/defn routes :- k/Function "Creates a ring handler of multiples handlers, matches in order." - [ring-handlers :- [k/Function]] - (apply some-fn ring-handlers)) + [ring-handlers :- [(s/maybe k/Function)]] + (apply some-fn (keep identity ring-handlers))) (s/defn match "Creates a ring-handler for given uri & request-method" diff --git a/src/kekkonen/swagger.clj b/src/kekkonen/swagger.clj index 07ad46d..52961ff 100644 --- a/src/kekkonen/swagger.clj +++ b/src/kekkonen/swagger.clj @@ -6,10 +6,15 @@ [kekkonen.core :as k] [kekkonen.common :as kc] [plumbing.core :as p] - [kekkonen.ring :as r])) + [kekkonen.ring :as r] + [clojure.string :as str])) -(def +default-swagger-ui-options+ - {:path "/"}) +(s/defschema Options + {(s/optional-key :ui) (s/maybe s/Str) + (s/optional-key :spec) (s/maybe s/Str) + (s/optional-key :data) k/KeywordMap + (s/optional-key :options) {(s/optional-key :ui) k/KeywordMap + (s/optional-key :spec) k/KeywordMap}}) (defn transform-handler "Transforms a handler into ring-swagger path->method->operation map." @@ -47,8 +52,11 @@ (s/defn swagger-ui "Ring handler for the Swagger UI" - [options] - (apply ui/swagger-ui (into [(:path options)] (apply concat (dissoc options :path))))) + [{:keys [ui spec] :as options}] + (when ui + (apply ui/swagger-ui (into [ui] (apply concat (merge + {:swagger-docs spec} + (-> options :options :ui))))))) (defn- add-base-path "Extracts the base path from the context and adds it to the swagger map as basePath" @@ -58,15 +66,16 @@ swagger)) (defn swagger-handler [swagger options] - (k/handler - {:type :kekkonen.ring/handler - :kekkonen.ring/method :get - :name "swagger.json" - :no-doc true} - (fn [{:keys [request] :as context}] - (let [dispatcher (k/get-dispatcher context) - ns (some-> context :request :query-params :ns str keyword) - handlers (k/available-handlers dispatcher ns (#'r/clean-context context))] - (ok (swagger-object - (add-base-path request (ring-swagger handlers swagger)) - options)))))) + (if-let [spec (:spec options)] + (k/handler + {:type :kekkonen.ring/handler + :kekkonen.ring/method :get + :name spec + :no-doc true} + (fn [{:keys [request] :as context}] + (let [dispatcher (k/get-dispatcher context) + ns (some-> context :request :query-params :ns str keyword) + handlers (k/available-handlers dispatcher ns (#'r/clean-context context))] + (ok (swagger-object + (add-base-path request (ring-swagger handlers swagger)) + (-> options :options :spec)))))))) diff --git a/test/kekkonen/api_test.clj b/test/kekkonen/api_test.clj index fa3d64a..caa75f6 100644 --- a/test/kekkonen/api_test.clj +++ b/test/kekkonen/api_test.clj @@ -301,6 +301,28 @@ :headers (contains {"Location" "/index.html"})}))))) +(facts "swagger-options" + + (fact "ui & spec are set to /swagger.json & / by default" + (let [app (api {:core {:handlers {:api #'plus}}})] + + (app {:uri "/swagger.json", :request-method :get}) => ok? + (app {:uri "/index.html", :request-method :get}) => ok?)) + + (fact "without ui & spec" + (let [app (api {:swagger {:spec nil, :ui nil} + :core {:handlers {:api #'plus}}})] + + (app {:uri "/swagger.json", :request-method :get}) => not-found? + (app {:uri "/", :request-method :get}) => not-found?)) + + (fact "with ui & spec" + (let [app (api {:swagger {:spec "/swagger.json", :ui "/api-docs"} + :core {:handlers {:api #'plus}}})] + + (app {:uri "/swagger.json", :request-method :get}) => ok? + (app {:uri "/api-docs/index.html", :request-method :get}) => ok?))) + (facts "api-meta" (fact "meta can be presented as maps or vector of tuples" (api {:core {:handlers {secret-ns [#'nada]}, :meta {::role require-role}}}) diff --git a/test/kekkonen/swagger_test.clj b/test/kekkonen/swagger_test.clj index ea2ae62..81a67cb 100644 --- a/test/kekkonen/swagger_test.clj +++ b/test/kekkonen/swagger_test.clj @@ -51,22 +51,21 @@ (fact "swagger-json can be generated" (s/with-fn-validation - (ks/swagger-object swagger {}) => truthy)))) + (ks/swagger-object swagger {}) => some?)))) (facts "swagger-handler" (let [dispatcher (k/transform-handlers (k/dispatcher {:handlers {:api {:admin #'echo}}}) (partial #'r/attach-ring-meta r/+default-options+)) - ctx {} - h (ks/swagger-handler {} {:info {:version "1.2.3"}})] + swagger-handler (ks/swagger-handler {} {:spec "swagger.json", :info {:version "1.2.3"}})] (against-background [(k/get-dispatcher anything) => dispatcher] - - (fact "generates swagger json" - (:body (h ctx)) => (contains {:paths (as-checker not-empty)}))) - - (fact "extracts swagger basePath from request context" - (let [context-path "/testpath"] - (:body (h {:request {:context context-path}})) => (contains {:basePath context-path}))) - - (fact "does not add basePath if no context" - (-> (h {:request {}}) :body :basePath) => nil?))) \ No newline at end of file + + (fact "generates swagger json" + (swagger-handler {}) => (contains {:body (contains {:paths seq})}))) + + (fact "extracts swagger basePath from request context" + (let [context-path "/testpath"] + (:body (swagger-handler {:request {:context context-path}})) => (contains {:basePath context-path}))) + + (fact "does not add basePath if no context" + (-> (swagger-handler {:request {}}) :body :basePath) => nil))) From 50b67c680b1ee745d05f5e96dfaea463982c2d5f Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Tue, 10 May 2016 07:37:21 +0300 Subject: [PATCH 3/5] By default, apis don't bind swagger-spec & swagger-ui --- CHANGES.md | 1 + dev-src/example/api.clj | 4 +++- dev-src/example/cqrs.clj | 4 ++-- dev-src/example/github/github.clj | 4 +++- examples/component/src/sample/handler.clj | 4 +++- src/kekkonen/api.clj | 5 +---- test/kekkonen/api_test.clj | 17 ++++++----------- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5710d3a..b12c48a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ * Support for Context-based urls, thanks to [Wout Neirynck](https://github.com/wneirynck). * *BREAKING*: top-level swagger options are now in align to the compojure-api: * Fixes [#22](https://github.com/metosin/kekkonen/issues/22) + * By default, `api`s don't bind swagger-spec & swagger-ui, use `:spec` & `:ui` options ### Old diff --git a/dev-src/example/api.clj b/dev-src/example/api.clj index 5da05a8..b046ab4 100644 --- a/dev-src/example/api.clj +++ b/dev-src/example/api.clj @@ -41,7 +41,9 @@ (def app (cqrs-api - {:swagger {:data {:info {:title "Kekkonen example"}}} + {:swagger {:ui "/api-docs" + :spec "/swagger.json" + :data {:info {:title "Kekkonen example"}}} :core {:handlers {:api {:pizza #'echo-pizza :sample [#'ping #'inc! #'plus]}} :context {:components {:counter (atom 0)}}}})) diff --git a/dev-src/example/cqrs.clj b/dev-src/example/cqrs.clj index 2430eba..3d23e20 100644 --- a/dev-src/example/cqrs.clj +++ b/dev-src/example/cqrs.clj @@ -105,8 +105,8 @@ (def app (cqrs-api - {:swagger {:spec "/swagger.json" - :ui "/api-docs" + {:swagger {:ui "/api-docs" + :spec "/swagger.json" :data {:info {:title "Kekkonen"}}} :core {:handlers {:api {:item [#'get-items #'add-item #'reset-items] :calculator [#'plus #'times #'increment] diff --git a/dev-src/example/github/github.clj b/dev-src/example/github/github.clj index fc5216a..cc27766 100644 --- a/dev-src/example/github/github.clj +++ b/dev-src/example/github/github.clj @@ -112,7 +112,9 @@ (def app (cqrs-api - {:swagger {:data {:info {:title "Kekkonen" + {:swagger {:ui "/api-docs" + :spec "/swagger.json" + :data {:info {:title "Kekkonen" :version "1.0"}}} :core {:handlers {:api {:github [#'get-repository #'list-repositorys diff --git a/examples/component/src/sample/handler.clj b/examples/component/src/sample/handler.clj index 03391d8..bfbef99 100644 --- a/examples/component/src/sample/handler.clj +++ b/examples/component/src/sample/handler.clj @@ -38,7 +38,9 @@ (p/defnk create [[:state counter]] (cqrs-api - {:swagger {:data {:info {:title "Kekkonen with Component" + {:swagger {:ui "/api-docs" + :spec "/swagger.json" + :data {:info {:title "Kekkonen with Component" :description "created with http://kekkonen.io"}}} :core {:handlers {:api {:pizza #'echo-pizza :math [#'inc! #'plus] diff --git a/src/kekkonen/api.clj b/src/kekkonen/api.clj index 86857d7..0d0a6f9 100644 --- a/src/kekkonen/api.clj +++ b/src/kekkonen/api.clj @@ -20,10 +20,7 @@ :api {:handlers r/+kekkonen-handlers+} :ring r/+default-options+ :mw mw/+default-options+ - ;; TODO: don't bind swagger.json & swagger-ui by default? - :swagger {:spec "/swagger.json" - :ui "/" - :data {:info {:title "Kekkonen API" + :swagger {:data {:info {:title "Kekkonen API" :version "0.0.1"}}}}) (defn api [options] diff --git a/test/kekkonen/api_test.clj b/test/kekkonen/api_test.clj index caa75f6..6266a66 100644 --- a/test/kekkonen/api_test.clj +++ b/test/kekkonen/api_test.clj @@ -21,7 +21,9 @@ context))) (facts "api-test" - (let [app (api {:core {:handlers {:api {:public [#'plus #'nada] + (let [app (api {:swagger {:ui "/api-docs" + :spec "/swagger.json"} + :core {:handlers {:api {:public [#'plus #'nada] secret-ns #'plus}} :meta {::role require-role}}})] @@ -294,25 +296,18 @@ {:/api/secret/plus anything})})))) (fact "swagger-ui" - (let [response (app {:uri "/" :request-method :get})] + (let [response (app {:uri "/api-docs" :request-method :get})] response => (contains {:status 302 :body "" :headers (contains - {"Location" "/index.html"})}))))) + {"Location" "/api-docs/index.html"})}))))) (facts "swagger-options" - (fact "ui & spec are set to /swagger.json & / by default" + (fact "ui & spec are not set by default" (let [app (api {:core {:handlers {:api #'plus}}})] - (app {:uri "/swagger.json", :request-method :get}) => ok? - (app {:uri "/index.html", :request-method :get}) => ok?)) - - (fact "without ui & spec" - (let [app (api {:swagger {:spec nil, :ui nil} - :core {:handlers {:api #'plus}}})] - (app {:uri "/swagger.json", :request-method :get}) => not-found? (app {:uri "/", :request-method :get}) => not-found?)) From 90f0a74ba1c44cb6d0b6cb93c18a37029c11f195 Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Tue, 10 May 2016 07:44:23 +0300 Subject: [PATCH 4/5] Added documentation --- CHANGES.md | 4 ++-- src/kekkonen/swagger.clj | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b12c48a..3be6ce3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,8 @@ ## 0.3.0-SNAPSHOT -* *BREAKING*: Removed type-level interceptors from ring-adapter. +* **BREAKING**: Removed type-level interceptors from ring-adapter. * Support for Context-based urls, thanks to [Wout Neirynck](https://github.com/wneirynck). -* *BREAKING*: top-level swagger options are now in align to the compojure-api: +* **BREAKING**: top-level swagger options are now in align to the compojure-api: * Fixes [#22](https://github.com/metosin/kekkonen/issues/22) * By default, `api`s don't bind swagger-spec & swagger-ui, use `:spec` & `:ui` options diff --git a/src/kekkonen/swagger.clj b/src/kekkonen/swagger.clj index 52961ff..fd6ff23 100644 --- a/src/kekkonen/swagger.clj +++ b/src/kekkonen/swagger.clj @@ -65,7 +65,9 @@ (assoc swagger :basePath context) swagger)) -(defn swagger-handler [swagger options] +(defn swagger-handler + "Creates a handler, that serves the swagger-spec" + [swagger options] (if-let [spec (:spec options)] (k/handler {:type :kekkonen.ring/handler From 73ac67c202a07325bfefdb0570d5967f9e295112 Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Tue, 10 May 2016 07:50:23 +0300 Subject: [PATCH 5/5] Re-indent tests --- test/kekkonen/swagger_test.clj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/kekkonen/swagger_test.clj b/test/kekkonen/swagger_test.clj index 81a67cb..deb019a 100644 --- a/test/kekkonen/swagger_test.clj +++ b/test/kekkonen/swagger_test.clj @@ -58,10 +58,10 @@ (k/dispatcher {:handlers {:api {:admin #'echo}}}) (partial #'r/attach-ring-meta r/+default-options+)) swagger-handler (ks/swagger-handler {} {:spec "swagger.json", :info {:version "1.2.3"}})] - (against-background [(k/get-dispatcher anything) => dispatcher] - (fact "generates swagger json" - (swagger-handler {}) => (contains {:body (contains {:paths seq})}))) + (against-background [(k/get-dispatcher anything) => dispatcher] + (fact "generates swagger json" + (swagger-handler {}) => (contains {:body (contains {:paths seq})}))) (fact "extracts swagger basePath from request context" (let [context-path "/testpath"]