diff --git a/modules/reitit-swagger/src/reitit/swagger.cljc b/modules/reitit-swagger/src/reitit/swagger.cljc index cc6f4e8e..4a2a5319 100644 --- a/modules/reitit-swagger/src/reitit/swagger.cljc +++ b/modules/reitit-swagger/src/reitit/swagger.cljc @@ -13,7 +13,6 @@ (s/def ::summary string?) (s/def ::description string?) (s/def ::operationId string?) -(s/def ::operationIds (s/coll-of ::operationId :distinct true)) (s/def ::swagger (s/keys :opt-un [::id])) (s/def ::spec (s/keys :opt-un [::swagger ::no-doc ::tags ::summary ::description ::operationId])) @@ -84,7 +83,6 @@ accept-route (fn [route] (-> route second :swagger :id (or ::default) (trie/into-set) (set/intersection ids) seq)) base-swagger-spec {:responses ^:displace {:default {:description ""}}} - oid-acc (atom []) transform-endpoint (fn [[method {{:keys [coercion no-doc swagger] :as data} :data middleware :middleware interceptors :interceptors}]] @@ -96,21 +94,13 @@ (apply meta-merge (keep (comp :swagger :data) interceptors)) (if coercion (coercion/get-apidocs coercion :swagger data)) - (select-keys data [:tags :summary :description]) - (let [oid (select-keys data [:operationId]) - oid-val (:operationId oid) - _ (when (not (nil? oid-val)) - (reset! oid-acc (conj @oid-acc oid-val)))] - oid) + (select-keys data [:tags :summary :description :operationId]) (strip-top-level-keys swagger))])) transform-path (fn [[p _ c]] (if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))] [(swagger-path p (r/options router)) endpoint])) map-in-order #(->> % (apply concat) (apply array-map)) - paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) map-in-order) - _ (when (not (s/valid? ::operationIds @oid-acc)) - (throw (ex-info (s/explain-str ::operationIds @oid-acc) {:operation-ids @oid-acc - :error "operationIds are not distinct"})))] + paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) map-in-order)] {:status 200 :body (meta-merge swagger {:paths paths})})) ([req res raise] diff --git a/test/cljc/reitit/swagger_test.clj b/test/cljc/reitit/swagger_test.clj index 4adafdc9..9c1ef38a 100644 --- a/test/cljc/reitit/swagger_test.clj +++ b/test/cljc/reitit/swagger_test.clj @@ -103,32 +103,6 @@ rrc/coerce-request-middleware rrc/coerce-response-middleware]}}))) -(def failing-app - (ring/ring-handler - (ring/router - ["/api" - {:swagger {:id ::math}} - - ["/swagger.json" - {:get {:no-doc true - :swagger {:info {:title "my-api"}} - :handler (swagger/create-swagger-handler)}}] - - ["/spec" {:coercion spec/coercion} - ["/plus/:z" - {:patch {:summary "patch" - :operationId "Patch" - :handler (constantly {:status 200})} - :options {:summary "options" - :operationId "Patch" - :middleware [{:data {:swagger {:responses {200 {:description "200"}}}}}] - :handler (constantly {:status 200})}}]]] - - {:data {:middleware [swagger/swagger-feature - rrc/coerce-exceptions-middleware - rrc/coerce-request-middleware - rrc/coerce-response-middleware]}}))) - (require '[fipp.edn]) (deftest swagger-test (testing "endpoints work" @@ -147,9 +121,6 @@ :uri "/api/schema/plus/3" :query-params {:x "2", :y "1"}}))))) - (testing "failing swagger-spec" - (is (thrown? clojure.lang.ExceptionInfo (:body (failing-app {:request-method :get - :uri "/api/swagger.json"}))))) (testing "swagger-spec" (let [spec (:body (app {:request-method :get :uri "/api/swagger.json"}))