Skip to content

Commit 806c9cb

Browse files
committed
Convert all swagger-routes
1 parent e5b5a49 commit 806c9cb

6 files changed

Lines changed: 70 additions & 72 deletions

File tree

examples/src/examples/thingie.clj

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323

2424
(def app
2525
(api
26-
(swagger-ui)
27-
(swagger-docs
28-
{:info {:version "1.0.0"
29-
:title "Thingies API"
30-
:description "the description"
31-
:termsOfService "http://www.metosin.fi"
32-
:contact {:name "My API Team"
33-
:email "foo@example.com"
34-
:url "http://www.metosin.fi"}
35-
:license {:name "Eclipse Public License"
36-
:url "http://www.eclipse.org/legal/epl-v10.html"}}
37-
:tags [{:name "math", :description "Math with parameters"}
38-
{:name "pizzas", :description "Pizza API"}
39-
{:name "failing", :description "Handling uncaught exceptions"}
40-
{:name "dates", :description "Dates API"}
41-
{:name "responses", :description "Responses demo"}
42-
{:name "primitives", :description "Returning primitive values"}
43-
{:name "context", :description "context routes"}
44-
{:name "echo", :description "Echoes data"}
45-
{:name "ordered", :description "Ordered routes"}
46-
{:name "file", :description "File upload"}]})
26+
{:swagger {:ui "/"
27+
:spec "/swagger.json"
28+
:data {:info {:version "1.0.0"
29+
:title "Thingies API"
30+
:description "the description"
31+
:termsOfService "http://www.metosin.fi"
32+
:contact {:name "My API Team"
33+
:email "foo@example.com"
34+
:url "http://www.metosin.fi"}
35+
:license {:name "Eclipse Public License"
36+
:url "http://www.eclipse.org/legal/epl-v10.html"}}
37+
:tags [{:name "math", :description "Math with parameters"}
38+
{:name "pizzas", :description "Pizza API"}
39+
{:name "failing", :description "Handling uncaught exceptions"}
40+
{:name "dates", :description "Dates API"}
41+
{:name "responses", :description "Responses demo"}
42+
{:name "primitives", :description "Returning primitive values"}
43+
{:name "context", :description "context routes"}
44+
{:name "echo", :description "Echoes data"}
45+
{:name "ordered", :description "Ordered routes"}
46+
{:name "file", :description "File upload"}]}}}
4747

4848
(context "/math" []
4949
:tags ["math"]

src/compojure/api/swagger.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
responses))))
2929
endpoint))
3030

31-
(defn- base-path [request]
31+
(defn base-path [request]
3232
(let [context (swagger/context request)]
3333
(if (= "" context) "/" context)))
3434

35-
(defn- swagger-spec-path
35+
(defn swagger-spec-path
3636
[app]
3737
(some-> app
3838
routes/get-routes

src/compojure/api/sweet.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838

3939
[compojure.api.swagger
4040

41-
swagger-ui
42-
swagger-docs
4341
swagger-routes]
4442

4543
[ring.swagger.json-schema

test/compojure/api/integration_test.clj

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
(fact ":responses"
246246
(fact "normal cases"
247247
(let [app (api
248-
(swagger-docs)
248+
(swagger-routes)
249249
(GET "/lotto/:x" []
250250
:path-params [x :- Long]
251251
:responses {403 {:schema [String]}
@@ -451,7 +451,7 @@
451451
(fact "swagger-docs"
452452
(let [app (api
453453
{:format {:formats [:json-kw :edn]}}
454-
(swagger-docs)
454+
(swagger-routes)
455455
(GET "/user" []
456456
(continue)))]
457457

@@ -467,7 +467,7 @@
467467

468468
(facts "swagger-docs with anonymous Return and Body models"
469469
(let [app (api
470-
(swagger-docs)
470+
(swagger-routes)
471471
(POST "/echo" []
472472
:return (s/either {:a String})
473473
:body [_ (s/maybe {:a String})]
@@ -496,7 +496,7 @@
496496

497497
(facts "https://github.com/metosin/compojure-api/issues/53"
498498
(let [app (api
499-
(swagger-docs)
499+
(swagger-routes)
500500
(POST "/" []
501501
:return ReturnValue
502502
:body [_ Boundary]
@@ -522,7 +522,7 @@
522522
; https://github.com/metosin/compojure-api/issues/94
523523
(facts "preserves deeply nested schema names"
524524
(let [app (api
525-
(swagger-docs)
525+
(swagger-routes)
526526
(POST "/" []
527527
:return Urho
528528
:body [_ Olipa]
@@ -539,7 +539,7 @@
539539

540540
(fact "swagger-docs works with the :middleware"
541541
(let [app (api
542-
(swagger-docs)
542+
(swagger-routes)
543543
(GET "/middleware" []
544544
:query-params [x :- String]
545545
:middleware [[constant-middleware (ok 1)]]
@@ -562,7 +562,7 @@
562562
(= body response)))
563563
not-ok? (comp not ok?)
564564
app (api
565-
(swagger-docs)
565+
(swagger-routes {:ui nil})
566566
(GET "/" [] ok)
567567
(GET "/a" [] ok)
568568
(context "/b" []
@@ -635,7 +635,7 @@
635635

636636
(fact "external deep schemas"
637637
(let [app (api
638-
(swagger-docs)
638+
(swagger-routes)
639639
burger-routes
640640
(POST "/pizza" []
641641
:return Pizza
@@ -659,7 +659,7 @@
659659

660660
(fact "multiple routes with same path & method in same file"
661661
(let [app (api
662-
(swagger-docs)
662+
(swagger-routes)
663663
(GET "/ping" []
664664
:summary "active-ping"
665665
(ok {:ping "active"}))
@@ -677,7 +677,7 @@
677677

678678
(fact "multiple routes with same path & method over context"
679679
(let [app (api
680-
(swagger-docs)
680+
(swagger-routes)
681681
(context "/api" []
682682
(context "/ipa" []
683683
(GET "/ping" []
@@ -699,7 +699,7 @@
699699

700700
(fact "multiple routes with same overall path (with different path sniplets & method over context"
701701
(let [app (api
702-
(swagger-docs)
702+
(swagger-routes)
703703
(context "/api/ipa" []
704704
(GET "/ping" []
705705
:summary "active-ping"
@@ -721,7 +721,7 @@
721721
; https://github.com/metosin/compojure-api/issues/98
722722
; https://github.com/metosin/compojure-api/issues/134
723723
(fact "basePath"
724-
(let [app (api (swagger-docs))]
724+
(let [app (api (swagger-routes))]
725725

726726
(fact "no context"
727727
(-> app get-spec :basePath) => "/")
@@ -730,11 +730,11 @@
730730
(against-background (rsc/context anything) => "/v2")
731731
(-> app get-spec :basePath) => "/v2"))
732732

733-
(let [app (api (swagger-docs {:basePath "/serve/from/here"}))]
733+
(let [app (api (swagger-routes {:data {:basePath "/serve/from/here"}}))]
734734
(fact "override it"
735735
(-> app get-spec :basePath) => "/serve/from/here"))
736736

737-
(let [app (api (swagger-docs {:basePath "/"}))]
737+
(let [app (api (swagger-routes {:data {:basePath "/"}}))]
738738
(fact "can set it to the default"
739739
(-> app get-spec :basePath) => "/")))
740740

@@ -745,7 +745,7 @@
745745

746746
(fact "api-spec with 2 schemas with non-equal contents"
747747
(let [app (api
748-
(swagger-docs)
748+
(swagger-routes)
749749
(GET "/" []
750750
:responses {200 {:schema (s/schema-with-name {:a {:d #"\D"}} "Kikka")}
751751
201 {:schema (s/schema-with-name {:a {:d #"\D"}} "Kikka")}}
@@ -760,7 +760,7 @@
760760

761761
(fact "anonymous body models over defined routes"
762762
(let [app (api
763-
(swagger-docs)
763+
(swagger-routes)
764764
over-the-hills-and-far-away)]
765765
(fact "generated model doesn't have namespaced keys"
766766
(-> app get-spec :definitions vals first :properties keys first) => :a)))
@@ -785,7 +785,7 @@
785785

786786
(fact "response descriptions"
787787
(let [app (api
788-
(swagger-docs)
788+
(swagger-routes)
789789
response-descriptions-routes)]
790790
(-> app get-spec :paths vals first :get :responses :500 :description) => "Horror"))
791791

@@ -794,7 +794,7 @@
794794
{:exceptions {:handlers {::ex/request-validation custom-validation-error-handler
795795
::ex/request-parsing custom-validation-error-handler
796796
::ex/response-validation custom-validation-error-handler}}}
797-
(swagger-docs)
797+
(swagger-routes)
798798
(POST "/get-long" []
799799
:body [body {:x Long}]
800800
:return Long
@@ -826,7 +826,7 @@
826826
(let [app (api
827827
{:exceptions {:handlers {::ex/default custom-exception-handler
828828
::custom-error custom-error-handler}}}
829-
(swagger-docs)
829+
(swagger-routes)
830830
(GET "/some-exception" []
831831
(throw (new RuntimeException)))
832832
(GET "/some-error" []
@@ -887,7 +887,7 @@
887887
(fact "ring-swagger options"
888888
(let [app (api
889889
{:ring-swagger {:default-response-description-fn status/get-description}}
890-
(swagger-docs)
890+
(swagger-routes)
891891
(GET "/ping" []
892892
:responses {500 nil}
893893
identity))]
@@ -948,19 +948,19 @@
948948

949949
(fact "swagger-spec-path"
950950
(fact "defaults to /swagger.json"
951-
(let [app (api (swagger-docs))]
952-
(#'swagger/swagger-spec-path app) => "/swagger.json"))
951+
(let [app (api (swagger-routes))]
952+
(swagger/swagger-spec-path app) => "/swagger.json"))
953953
(fact "follows defined path"
954-
(let [app (api (swagger-docs "/api/api-docs/swagger.json"))]
955-
(#'swagger/swagger-spec-path app) => "/api/api-docs/swagger.json")))
954+
(let [app (api (swagger-routes {:spec "/api/api-docs/swagger.json"}))]
955+
(swagger/swagger-spec-path app) => "/api/api-docs/swagger.json")))
956956

957957
(defrecord NonSwaggerRecord [data])
958958

959959
(fact "api validation"
960960

961961
(fact "a swagger api with valid swagger records"
962962
(let [app (api
963-
(swagger-docs)
963+
(swagger-routes)
964964
(GET "/ping" []
965965
:return {:data s/Str}
966966
(ok {:data "ping"})))]
@@ -975,7 +975,7 @@
975975

976976
(fact "a swagger api with invalid swagger records"
977977
(let [app (api
978-
(swagger-docs)
978+
(swagger-routes)
979979
(GET "/ping" []
980980
:return NonSwaggerRecord
981981
(ok (->NonSwaggerRecord "ping"))))]
@@ -1045,7 +1045,7 @@
10451045

10461046
(fact ":swagger params just for ducumentation"
10471047
(let [app (api
1048-
(swagger-docs)
1048+
(swagger-routes)
10491049
(GET "/route" [q]
10501050
:swagger {:x-name :boolean
10511051
:operationId "echoBoolean"
@@ -1073,9 +1073,10 @@
10731073
(fact "more swagger-data can be (deep-)merged in - either via swagger-docs at runtime via mws, fixes #170"
10741074
(let [app (api
10751075
(middleware [[rsm/wrap-swagger-data {:paths {"/runtime" {:get {}}}}]]
1076-
(swagger-docs
1077-
{:info {:version "2.0.0"}
1078-
:paths {"/extra" {:get {}}}})
1076+
(swagger-routes
1077+
{:data
1078+
{:info {:version "2.0.0"}
1079+
:paths {"/extra" {:get {}}}}})
10791080
(GET "/normal" [] (ok))))]
10801081
(get-spec app) => (contains
10811082
{:paths (just
@@ -1087,14 +1088,14 @@
10871088
(s/defschema Foo {:a [s/Keyword]})
10881089

10891090
(defapi with-defapi
1090-
(swagger-docs)
1091+
(swagger-routes)
10911092
(GET "/foo" []
10921093
:return Foo
10931094
(ok {:a "foo"})))
10941095

10951096
(defn with-api []
10961097
(api
1097-
(swagger-docs)
1098+
(swagger-routes)
10981099
(GET "/foo" []
10991100
:return Foo
11001101
(ok {:a "foo"}))))
@@ -1169,8 +1170,7 @@
11691170
(fact "using local symbols for restructuring params"
11701171
(let [responses {400 {:schema {:fail s/Str}}}
11711172
app (api
1172-
(swagger-docs
1173-
{:info {:version "2.0.0"}})
1173+
{:swagger {:data {:info {:version "2.0.0"}}}}
11741174
(GET "/a" []
11751175
:responses responses
11761176
:return {:ok s/Str}

test/compojure/api/routes_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
(ok {:message (str "Hello, " name)}))
5050
(more-routes version)))
5151
app (api
52-
(swagger-docs)
52+
(swagger-routes)
5353
routes)]
5454

5555
(fact "all routes can be invoked"
@@ -95,7 +95,7 @@
9595
:path-params [version :- String]
9696
(more-routes version))
9797
app (api
98-
(swagger-docs)
98+
(swagger-routes)
9999
routes)]
100100

101101
(fact "all routes can be invoked"
@@ -118,7 +118,7 @@
118118

119119
(fact "route merging"
120120
(routes/get-routes (routes (routes))) => []
121-
(routes/get-routes (routes (swagger-ui))) => []
121+
(routes/get-routes (routes (swagger-routes {:spec nil}))) => []
122122
(routes/get-routes (routes (routes (GET "/ping" [] "pong")))) => [["/ping" :get {}]])
123123

124124
(fact "invalid route options"

test/compojure/api/sweet_test.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818

1919
(def app
2020
(api
21-
(swagger-docs
22-
{:info {:version "1.0.0"
23-
:title "Sausages"
24-
:description "Sausage description"
25-
:termsOfService "http://helloreverb.com/terms/"
26-
:contact {:name "My API Team"
27-
:email "foo@example.com"
28-
:url "http://www.metosin.fi"}
29-
:license {:name "Eclipse Public License"
30-
:url "http://www.eclipse.org/legal/epl-v10.html"}}})
21+
{:swagger {:spec "/swagger.json"
22+
:data {:info {:version "1.0.0"
23+
:title "Sausages"
24+
:description "Sausage description"
25+
:termsOfService "http://helloreverb.com/terms/"
26+
:contact {:name "My API Team"
27+
:email "foo@example.com"
28+
:url "http://www.metosin.fi"}
29+
:license {:name "Eclipse Public License"
30+
:url "http://www.eclipse.org/legal/epl-v10.html"}}}}}
3131
ping-route
3232
(context "/api" []
3333
ping-route

0 commit comments

Comments
 (0)