From 87051448d61477169e716e54c646023ea413874f Mon Sep 17 00:00:00 2001 From: Hugh Powell Date: Tue, 18 Apr 2023 19:27:29 +1000 Subject: [PATCH] Remove a nil :definitions key --- src/spec_tools/swagger/core.cljc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/spec_tools/swagger/core.cljc b/src/spec_tools/swagger/core.cljc index f27ec2b..0a7ee9e 100644 --- a/src/spec_tools/swagger/core.cljc +++ b/src/spec_tools/swagger/core.cljc @@ -239,11 +239,14 @@ x)) x))) -(defn- raise-refs-to-top [x] - (cond-> x - (:paths x) (-> - (assoc :definitions (apply merge (map :definitions (mapcat vals (vals (:paths x)))))) - (update :paths update-vals (fn [path] (update-vals path #(dissoc % :definitions))))))) +(defn- raise-refs-to-top [swagger-doc] + (let [swagger-doc' + (cond-> swagger-doc + (:paths swagger-doc) (-> + (assoc :definitions (apply merge (map :definitions (mapcat vals (vals (:paths swagger-doc)))))) + (update :paths update-vals (fn [path] (update-vals path #(dissoc % :definitions))))))] + (cond-> swagger-doc' + (nil? (:definitions swagger-doc')) (dissoc swagger-doc' :definitions)))) ;; ;; generate the swagger spec