Fork me on GitHub
#reitit
<
2023-08-14
>
hanDerPeder08:08:39

(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".

opqdonut08:08:26

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
opqdonut08:08:02

This and https://github.com/metosin/reitit/issues/627 are pretty much the blockers for a non-alpha openapi reitit release.

opqdonut08:08:02
replied to a thread: (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]}] (&lt; 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) -&gt;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) + (-&gt; 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".

This and https://github.com/metosin/reitit/issues/627 are pretty much the blockers for a non-alpha openapi reitit release.