refactor: no need to pass options into -get-apidocs-openapi

This commit is contained in:
Joel Kaasinen 2023-08-28 08:59:58 +03:00
parent ee298ec362
commit f943b025cb

View file

@ -133,12 +133,8 @@
;; malli options ;; malli options
:options nil}) :options nil})
;; TODO: this is now seems like a generic transforming function that could be used in all of malli, spec, schema
;; ... just tranform the schemas in place
;; also, this has internally massive amount of duplicate code, could be simplified
;; ... tests too
(defn -get-apidocs-openapi (defn -get-apidocs-openapi
[coercion {:keys [request parameters responses content-types] :or {content-types ["application/json"]}} options] [coercion {:keys [request parameters responses content-types] :or {content-types ["application/json"]}}]
(let [{:keys [body multipart]} parameters (let [{:keys [body multipart]} parameters
parameters (dissoc parameters :request :body :multipart) parameters (dissoc parameters :request :body :multipart)
->content (fn [data schema] ->content (fn [data schema]
@ -146,7 +142,7 @@
{:schema schema} {:schema schema}
(select-keys data [:description :examples]) (select-keys data [:description :examples])
(:openapi data))) (:openapi data)))
->schema-object #(coercion/-get-model-apidocs coercion :openapi %1 (merge options %2))] ->schema-object #(coercion/-get-model-apidocs coercion :openapi %1 %2)]
(merge (merge
(when (seq parameters) (when (seq parameters)
{:parameters {:parameters
@ -243,7 +239,7 @@
(-get-options [_] opts) (-get-options [_] opts)
(-get-model-apidocs [this specification model options] (-get-model-apidocs [this specification model options]
(case specification (case specification
:openapi (json-schema/transform model options) :openapi (json-schema/transform model (merge opts options))
(throw (throw
(ex-info (ex-info
(str "Can't produce Malli apidocs for " specification) (str "Can't produce Malli apidocs for " specification)
@ -268,7 +264,7 @@
(if (:schema $) (if (:schema $)
(update $ :schema swagger/transform {:type :schema}) (update $ :schema swagger/transform {:type :schema})
$))]))})) $))]))}))
:openapi (-get-apidocs-openapi this data options) :openapi (-get-apidocs-openapi this data)
(throw (throw
(ex-info (ex-info
(str "Can't produce Malli apidocs for " specification) (str "Can't produce Malli apidocs for " specification)