Skip to content

Commit a1a9638

Browse files
committed
feat: better error reporting while building openapi docs
1 parent 7520d20 commit a1a9638

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

modules/reitit-openapi/src/reitit/openapi.clj

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,23 @@
206206
accept-route (fn [route]
207207
(-> route second :openapi :id (or ::default) (trie/into-set) (set/intersection ids) seq))
208208
definitions (volatile! {})
209-
transform-endpoint (fn [[method {{:keys [coercion no-doc openapi] :as data} :data
210-
middleware :middleware
211-
interceptors :interceptors}]]
212-
(if (and data (not no-doc))
213-
[method
214-
(meta-merge
215-
(apply meta-merge (keep (comp :openapi :data) middleware))
216-
(apply meta-merge (keep (comp :openapi :data) interceptors))
217-
(if coercion
218-
(-get-apidocs-openapi coercion data definitions))
219-
(select-keys data [:tags :summary :description])
220-
(strip-top-level-keys openapi))]))
209+
transform-endpoint (fn [path [method {{:keys [coercion no-doc openapi] :as data} :data
210+
middleware :middleware
211+
interceptors :interceptors}]]
212+
(try
213+
(if (and data (not no-doc))
214+
[method
215+
(meta-merge
216+
(apply meta-merge (keep (comp :openapi :data) middleware))
217+
(apply meta-merge (keep (comp :openapi :data) interceptors))
218+
(if coercion
219+
(-get-apidocs-openapi coercion data definitions))
220+
(select-keys data [:tags :summary :description])
221+
(strip-top-level-keys openapi))])
222+
(catch Throwable t
223+
(throw (ex-info "While building openapi docs" {:path path :method method})))))
221224
transform-path (fn [[p _ c]]
222-
(if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))]
225+
(if-let [endpoint (some->> c (keep (partial transform-endpoint p)) (seq) (into {}))]
223226
[(openapi-path p (r/options router)) endpoint]))
224227
map-in-order #(->> % (apply concat) (apply array-map))
225228
paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) map-in-order)]

0 commit comments

Comments
 (0)