|
245 | 245 | (fact ":responses" |
246 | 246 | (fact "normal cases" |
247 | 247 | (let [app (api |
248 | | - (swagger-docs) |
| 248 | + (swagger-routes) |
249 | 249 | (GET "/lotto/:x" [] |
250 | 250 | :path-params [x :- Long] |
251 | 251 | :responses {403 {:schema [String]} |
|
451 | 451 | (fact "swagger-docs" |
452 | 452 | (let [app (api |
453 | 453 | {:format {:formats [:json-kw :edn]}} |
454 | | - (swagger-docs) |
| 454 | + (swagger-routes) |
455 | 455 | (GET "/user" [] |
456 | 456 | (continue)))] |
457 | 457 |
|
|
467 | 467 |
|
468 | 468 | (facts "swagger-docs with anonymous Return and Body models" |
469 | 469 | (let [app (api |
470 | | - (swagger-docs) |
| 470 | + (swagger-routes) |
471 | 471 | (POST "/echo" [] |
472 | 472 | :return (s/either {:a String}) |
473 | 473 | :body [_ (s/maybe {:a String})] |
|
496 | 496 |
|
497 | 497 | (facts "https://github.com/metosin/compojure-api/issues/53" |
498 | 498 | (let [app (api |
499 | | - (swagger-docs) |
| 499 | + (swagger-routes) |
500 | 500 | (POST "/" [] |
501 | 501 | :return ReturnValue |
502 | 502 | :body [_ Boundary] |
|
522 | 522 | ; https://github.com/metosin/compojure-api/issues/94 |
523 | 523 | (facts "preserves deeply nested schema names" |
524 | 524 | (let [app (api |
525 | | - (swagger-docs) |
| 525 | + (swagger-routes) |
526 | 526 | (POST "/" [] |
527 | 527 | :return Urho |
528 | 528 | :body [_ Olipa] |
|
539 | 539 |
|
540 | 540 | (fact "swagger-docs works with the :middleware" |
541 | 541 | (let [app (api |
542 | | - (swagger-docs) |
| 542 | + (swagger-routes) |
543 | 543 | (GET "/middleware" [] |
544 | 544 | :query-params [x :- String] |
545 | 545 | :middleware [[constant-middleware (ok 1)]] |
|
562 | 562 | (= body response))) |
563 | 563 | not-ok? (comp not ok?) |
564 | 564 | app (api |
565 | | - (swagger-docs) |
| 565 | + (swagger-routes {:ui nil}) |
566 | 566 | (GET "/" [] ok) |
567 | 567 | (GET "/a" [] ok) |
568 | 568 | (context "/b" [] |
|
635 | 635 |
|
636 | 636 | (fact "external deep schemas" |
637 | 637 | (let [app (api |
638 | | - (swagger-docs) |
| 638 | + (swagger-routes) |
639 | 639 | burger-routes |
640 | 640 | (POST "/pizza" [] |
641 | 641 | :return Pizza |
|
659 | 659 |
|
660 | 660 | (fact "multiple routes with same path & method in same file" |
661 | 661 | (let [app (api |
662 | | - (swagger-docs) |
| 662 | + (swagger-routes) |
663 | 663 | (GET "/ping" [] |
664 | 664 | :summary "active-ping" |
665 | 665 | (ok {:ping "active"})) |
|
677 | 677 |
|
678 | 678 | (fact "multiple routes with same path & method over context" |
679 | 679 | (let [app (api |
680 | | - (swagger-docs) |
| 680 | + (swagger-routes) |
681 | 681 | (context "/api" [] |
682 | 682 | (context "/ipa" [] |
683 | 683 | (GET "/ping" [] |
|
699 | 699 |
|
700 | 700 | (fact "multiple routes with same overall path (with different path sniplets & method over context" |
701 | 701 | (let [app (api |
702 | | - (swagger-docs) |
| 702 | + (swagger-routes) |
703 | 703 | (context "/api/ipa" [] |
704 | 704 | (GET "/ping" [] |
705 | 705 | :summary "active-ping" |
|
721 | 721 | ; https://github.com/metosin/compojure-api/issues/98 |
722 | 722 | ; https://github.com/metosin/compojure-api/issues/134 |
723 | 723 | (fact "basePath" |
724 | | - (let [app (api (swagger-docs))] |
| 724 | + (let [app (api (swagger-routes))] |
725 | 725 |
|
726 | 726 | (fact "no context" |
727 | 727 | (-> app get-spec :basePath) => "/") |
|
730 | 730 | (against-background (rsc/context anything) => "/v2") |
731 | 731 | (-> app get-spec :basePath) => "/v2")) |
732 | 732 |
|
733 | | - (let [app (api (swagger-docs {:basePath "/serve/from/here"}))] |
| 733 | + (let [app (api (swagger-routes {:data {:basePath "/serve/from/here"}}))] |
734 | 734 | (fact "override it" |
735 | 735 | (-> app get-spec :basePath) => "/serve/from/here")) |
736 | 736 |
|
737 | | - (let [app (api (swagger-docs {:basePath "/"}))] |
| 737 | + (let [app (api (swagger-routes {:data {:basePath "/"}}))] |
738 | 738 | (fact "can set it to the default" |
739 | 739 | (-> app get-spec :basePath) => "/"))) |
740 | 740 |
|
|
745 | 745 |
|
746 | 746 | (fact "api-spec with 2 schemas with non-equal contents" |
747 | 747 | (let [app (api |
748 | | - (swagger-docs) |
| 748 | + (swagger-routes) |
749 | 749 | (GET "/" [] |
750 | 750 | :responses {200 {:schema (s/schema-with-name {:a {:d #"\D"}} "Kikka")} |
751 | 751 | 201 {:schema (s/schema-with-name {:a {:d #"\D"}} "Kikka")}} |
|
760 | 760 |
|
761 | 761 | (fact "anonymous body models over defined routes" |
762 | 762 | (let [app (api |
763 | | - (swagger-docs) |
| 763 | + (swagger-routes) |
764 | 764 | over-the-hills-and-far-away)] |
765 | 765 | (fact "generated model doesn't have namespaced keys" |
766 | 766 | (-> app get-spec :definitions vals first :properties keys first) => :a))) |
|
785 | 785 |
|
786 | 786 | (fact "response descriptions" |
787 | 787 | (let [app (api |
788 | | - (swagger-docs) |
| 788 | + (swagger-routes) |
789 | 789 | response-descriptions-routes)] |
790 | 790 | (-> app get-spec :paths vals first :get :responses :500 :description) => "Horror")) |
791 | 791 |
|
|
794 | 794 | {:exceptions {:handlers {::ex/request-validation custom-validation-error-handler |
795 | 795 | ::ex/request-parsing custom-validation-error-handler |
796 | 796 | ::ex/response-validation custom-validation-error-handler}}} |
797 | | - (swagger-docs) |
| 797 | + (swagger-routes) |
798 | 798 | (POST "/get-long" [] |
799 | 799 | :body [body {:x Long}] |
800 | 800 | :return Long |
|
826 | 826 | (let [app (api |
827 | 827 | {:exceptions {:handlers {::ex/default custom-exception-handler |
828 | 828 | ::custom-error custom-error-handler}}} |
829 | | - (swagger-docs) |
| 829 | + (swagger-routes) |
830 | 830 | (GET "/some-exception" [] |
831 | 831 | (throw (new RuntimeException))) |
832 | 832 | (GET "/some-error" [] |
|
887 | 887 | (fact "ring-swagger options" |
888 | 888 | (let [app (api |
889 | 889 | {:ring-swagger {:default-response-description-fn status/get-description}} |
890 | | - (swagger-docs) |
| 890 | + (swagger-routes) |
891 | 891 | (GET "/ping" [] |
892 | 892 | :responses {500 nil} |
893 | 893 | identity))] |
|
948 | 948 |
|
949 | 949 | (fact "swagger-spec-path" |
950 | 950 | (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")) |
953 | 953 | (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"))) |
956 | 956 |
|
957 | 957 | (defrecord NonSwaggerRecord [data]) |
958 | 958 |
|
959 | 959 | (fact "api validation" |
960 | 960 |
|
961 | 961 | (fact "a swagger api with valid swagger records" |
962 | 962 | (let [app (api |
963 | | - (swagger-docs) |
| 963 | + (swagger-routes) |
964 | 964 | (GET "/ping" [] |
965 | 965 | :return {:data s/Str} |
966 | 966 | (ok {:data "ping"})))] |
|
975 | 975 |
|
976 | 976 | (fact "a swagger api with invalid swagger records" |
977 | 977 | (let [app (api |
978 | | - (swagger-docs) |
| 978 | + (swagger-routes) |
979 | 979 | (GET "/ping" [] |
980 | 980 | :return NonSwaggerRecord |
981 | 981 | (ok (->NonSwaggerRecord "ping"))))] |
|
1045 | 1045 |
|
1046 | 1046 | (fact ":swagger params just for ducumentation" |
1047 | 1047 | (let [app (api |
1048 | | - (swagger-docs) |
| 1048 | + (swagger-routes) |
1049 | 1049 | (GET "/route" [q] |
1050 | 1050 | :swagger {:x-name :boolean |
1051 | 1051 | :operationId "echoBoolean" |
|
1073 | 1073 | (fact "more swagger-data can be (deep-)merged in - either via swagger-docs at runtime via mws, fixes #170" |
1074 | 1074 | (let [app (api |
1075 | 1075 | (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 {}}}}}) |
1079 | 1080 | (GET "/normal" [] (ok))))] |
1080 | 1081 | (get-spec app) => (contains |
1081 | 1082 | {:paths (just |
|
1087 | 1088 | (s/defschema Foo {:a [s/Keyword]}) |
1088 | 1089 |
|
1089 | 1090 | (defapi with-defapi |
1090 | | - (swagger-docs) |
| 1091 | + (swagger-routes) |
1091 | 1092 | (GET "/foo" [] |
1092 | 1093 | :return Foo |
1093 | 1094 | (ok {:a "foo"}))) |
1094 | 1095 |
|
1095 | 1096 | (defn with-api [] |
1096 | 1097 | (api |
1097 | | - (swagger-docs) |
| 1098 | + (swagger-routes) |
1098 | 1099 | (GET "/foo" [] |
1099 | 1100 | :return Foo |
1100 | 1101 | (ok {:a "foo"})))) |
|
1169 | 1170 | (fact "using local symbols for restructuring params" |
1170 | 1171 | (let [responses {400 {:schema {:fail s/Str}}} |
1171 | 1172 | app (api |
1172 | | - (swagger-docs |
1173 | | - {:info {:version "2.0.0"}}) |
| 1173 | + {:swagger {:data {:info {:version "2.0.0"}}}} |
1174 | 1174 | (GET "/a" [] |
1175 | 1175 | :responses responses |
1176 | 1176 | :return {:ok s/Str} |
|
0 commit comments