Skip to content

Commit

Permalink
refactor: get rid of reitit.coercion/get-apidocs
Browse files Browse the repository at this point in the history
  • Loading branch information
opqdonut committed Aug 28, 2023
1 parent 233ac19 commit 8af89c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
31 changes: 0 additions & 31 deletions modules/reitit-core/src/reitit/coercion.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -191,37 +191,6 @@
(defn -compile-parameters [data coercion]
(impl/path-update data [[[:parameters any?] #(-compile-model coercion % nil)]]))

;;
;; api-docs
;;

(defn -warn-unsupported-coercions [{:keys [request responses] :as _data}]
(when request
(println "WARNING [reitit.coercion]: swagger apidocs don't support :request coercion"))
(when (some :content (vals responses))
(println "WARNING [reitit.coercion]: swagger apidocs don't support :responses :content coercion")))

(defn get-apidocs [coercion specification data]
(let [swagger-parameter {:query :query
:body :body
:form :formData
:header :header
:path :path
:multipart :formData}]
(case specification
;; :openapi handled in reitit.openapi
:swagger (do
(-warn-unsupported-coercions data)
(->> (update
data
:parameters
(fn [parameters]
(->> parameters
(map (fn [[k v]] [(swagger-parameter k) v]))
(filter first)
(into {}))))
(-get-apidocs coercion specification))))))

;;
;; integration
;;
Expand Down
26 changes: 25 additions & 1 deletion modules/reitit-swagger/src/reitit/swagger.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@
(defn- swagger-path [path opts]
(-> path (trie/normalize opts) (str/replace #"\{\*" "{")))

(defn -warn-unsupported-coercions [{:keys [request responses] :as _data}]
(when request
(println "WARNING [reitit.coercion]: swagger apidocs don't support :request coercion"))
(when (some :content (vals responses))
(println "WARNING [reitit.coercion]: swagger apidocs don't support :responses :content coercion")))

(defn -get-swagger-apidocs [coercion data]
(let [swagger-parameter {:query :query
:body :body
:form :formData
:header :header
:path :path
:multipart :formData}]
(-warn-unsupported-coercions data)
(->> (update
data
:parameters
(fn [parameters]
(->> parameters
(map (fn [[k v]] [(swagger-parameter k) v]))
(filter first)
(into {}))))
(coercion/-get-apidocs coercion :swagger))))

(defn create-swagger-handler
"Create a ring handler to emit swagger spec. Collects all routes from router which have
an intersecting `[:swagger :id]` and which are not marked with `:no-doc` route data."
Expand All @@ -95,7 +119,7 @@
(apply meta-merge (keep (comp :swagger :data) middleware))
(apply meta-merge (keep (comp :swagger :data) interceptors))
(if coercion
(coercion/get-apidocs coercion :swagger data))
(-get-swagger-apidocs coercion data))
(select-keys data [:tags :summary :description :operationId])
(strip-top-level-keys swagger))]))
transform-path (fn [[p _ c]]
Expand Down

0 comments on commit 8af89c0

Please sign in to comment.