This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-14
Channels
- # announcements (31)
- # babashka (9)
- # beginners (4)
- # calva (67)
- # cider (6)
- # clj-yaml (10)
- # clojure (105)
- # clojure-austin (8)
- # clojure-bay-area (1)
- # clojure-europe (12)
- # clojure-germany (3)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (2)
- # clojurescript (5)
- # core-logic (4)
- # data-science (29)
- # datomic (6)
- # dev-tooling (5)
- # emacs (3)
- # hyperfiddle (22)
- # introduce-yourself (4)
- # lsp (8)
- # malli (10)
- # off-topic (8)
- # pathom (74)
- # polylith (39)
- # practicalli (1)
- # reitit (3)
- # shadow-cljs (2)
- # spacemacs (3)
- # squint (4)
- # tools-deps (4)
(reitit.coercion.malli/-get-apidocs-openapi
(reitit.coercion.malli/create)
{:parameters {:query [:and {:registry {::foo string?}}
[:map [:x :int] [:y :int] [:foo ::foo]]
[:fn (fn [{:keys [x y]}]
(< x y))]]}}
nil)
This fails in several ways:
1. https://github.com/metosin/reitit/issues/558 deals with swagger, but it's also the case for openapi
2. -get-apidocs-openapi
does not unroll / merge :and
, :or
, etc.. schemas
This patch fixes it for my needs, but not in the general case
diff --git a/modules/reitit-malli/src/reitit/coercion/malli.cljc b/modules/reitit-malli/src/reitit/coercion/malli.cljc
index 6f4dff5b..1b1b5860 100644
--- a/modules/reitit-malli/src/reitit/coercion/malli.cljc
+++ b/modules/reitit-malli/src/reitit/coercion/malli.cljc
@@ -136,10 +136,16 @@
(defn -get-apidocs-openapi
[coercion {:keys [parameters responses content-types] :or {content-types ["application/json"]}} options]
(let [{:keys [body request multipart]} parameters
+ definitions (volatile! {})
parameters (dissoc parameters :request :body :multipart)
->schema-object (fn [schema opts]
- (let [current-opts (merge options opts)]
- (json-schema/transform schema current-opts)))]
+ (let [current-opts (merge options opts)
+ ret (json-schema/transform schema current-opts)]
+ (vswap! definitions merge (:definitions ret))
+ ;; hack for :and schema
+ (if (contains? ret :allOf)
+ (-> ret :allOf first)
+ ret)))]
(merge
(when (seq parameters)
{:parameters
@@ -216,7 +222,10 @@
[status (merge (select-keys response [:description])
(when content
{:content content}))])))
- responses)}))))
+ responses)})
+
+ (when (seq @definitions)
+ {:definitions @definitions}))))
(defn create
([]
Is anybody working on this?
I could take a stab at it, but seems to be several cases to consider for a proper fix so I don't want to commit if it's already in someones pipeline.
Saw @ikitommi mentioned openapi support would be coming in "a few weeks".Sorry for the late reply and thanks for testing openapi support out! I'm intending to free some time to finnish all the stuff related to #589, hopefully next week. Feel free to ping me if you don't hear anything.
👍 2
This and https://github.com/metosin/reitit/issues/627 are pretty much the blockers for a non-alpha openapi reitit release.
This and https://github.com/metosin/reitit/issues/627 are pretty much the blockers for a non-alpha openapi reitit release.