Skip to content

Commit

Permalink
Extract child definition when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
HughPowell committed Sep 20, 2023
1 parent 65e8235 commit 98ffa58
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/spec_tools/swagger/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@

(defn- accept-merge [children]
;; Use x-anyOf and x-allOf instead of normal versions
{:type "object"
:properties (->> (concat children
(mapcat :x-anyOf children)
(mapcat :x-allOf children))
(map :properties)
(reduce merge {}))
;; Don't include top schema from s/or.
:required (->> (concat (remove :x-anyOf children)
(mapcat :x-allOf children))
(map :required)
(reduce into (sorted-set))
(into []))})
(let [children' (map #(if (contains? % :$ref)
(first (vals (::definitions %)))
%)
children)]
{:type "object"
:properties (->> (concat children'
(mapcat :x-anyOf children')
(mapcat :x-allOf children'))
(map :properties)
(reduce merge {}))
;; Don't include top schema from s/or.
:required (->> (concat (remove :x-anyOf children')
(mapcat :x-allOf children'))
(map :required)
(reduce into (sorted-set))
(into []))}))

(defmethod accept-spec 'clojure.spec.alpha/merge [_ _ children _]
(accept-merge children))
Expand Down

0 comments on commit 98ffa58

Please sign in to comment.