feat: better error reporting while building openapi docs

This commit is contained in:
Joel Kaasinen 2025-10-07 15:26:38 +03:00
parent 7520d20f12
commit a1a9638f82

View file

@ -206,20 +206,23 @@
accept-route (fn [route] accept-route (fn [route]
(-> route second :openapi :id (or ::default) (trie/into-set) (set/intersection ids) seq)) (-> route second :openapi :id (or ::default) (trie/into-set) (set/intersection ids) seq))
definitions (volatile! {}) definitions (volatile! {})
transform-endpoint (fn [[method {{:keys [coercion no-doc openapi] :as data} :data transform-endpoint (fn [path [method {{:keys [coercion no-doc openapi] :as data} :data
middleware :middleware middleware :middleware
interceptors :interceptors}]] interceptors :interceptors}]]
(if (and data (not no-doc)) (try
[method (if (and data (not no-doc))
(meta-merge [method
(apply meta-merge (keep (comp :openapi :data) middleware)) (meta-merge
(apply meta-merge (keep (comp :openapi :data) interceptors)) (apply meta-merge (keep (comp :openapi :data) middleware))
(if coercion (apply meta-merge (keep (comp :openapi :data) interceptors))
(-get-apidocs-openapi coercion data definitions)) (if coercion
(select-keys data [:tags :summary :description]) (-get-apidocs-openapi coercion data definitions))
(strip-top-level-keys openapi))])) (select-keys data [:tags :summary :description])
(strip-top-level-keys openapi))])
(catch Throwable t
(throw (ex-info "While building openapi docs" {:path path :method method})))))
transform-path (fn [[p _ c]] transform-path (fn [[p _ c]]
(if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))] (if-let [endpoint (some->> c (keep (partial transform-endpoint p)) (seq) (into {}))]
[(openapi-path p (r/options router)) endpoint])) [(openapi-path p (r/options router)) endpoint]))
map-in-order #(->> % (apply concat) (apply array-map)) map-in-order #(->> % (apply concat) (apply array-map))
paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) map-in-order)] paths (->> router (r/compiled-routes) (filter accept-route) (map transform-path) map-in-order)]