diff --git a/modules/reitit-malli/src/reitit/coercion/malli.cljc b/modules/reitit-malli/src/reitit/coercion/malli.cljc index 9b66f8fa..99226230 100644 --- a/modules/reitit-malli/src/reitit/coercion/malli.cljc +++ b/modules/reitit-malli/src/reitit/coercion/malli.cljc @@ -135,8 +135,8 @@ (defn -get-apidocs-openapi [coercion {:keys [parameters responses content-types] :or {content-types ["application/json"]}} options] - (let [{:keys [body request]} parameters - parameters (dissoc parameters :request :body) + (let [{:keys [body request multipart]} parameters + parameters (dissoc parameters :request :body :multipart) ->schema-object (fn [schema opts] (let [current-opts (merge options opts)] (json-schema/transform (coercion/-compile-model coercion schema current-opts) @@ -184,6 +184,14 @@ :content-type content-type})] [content-type {:schema schema}]))) (:content request)))}}) + (when multipart + {:requestBody + {:content + {"multipart/form-data" + {:schema + (->schema-object multipart {:in :requestBody + :type :schema + :content-type "multipart/form-data"})}}}}) (when responses {:responses (into {} diff --git a/test/cljc/reitit/openapi_test.clj b/test/cljc/reitit/openapi_test.clj index 0216ac8e..3f789a47 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -432,7 +432,11 @@ (deftest multipart-test (doseq [[coercion file-schema] - [#_[#'malli/coercion (fn [nom] [:map [nom :string]])] + [[#'malli/coercion [:map {:json-schema {:type "string" + :format "binary"}} + [:filename :string] + [:content-type :string] + [:bytes :int]]] #_[#'schema/coercion (fn [nom] {nom s/Str})] [#'spec/coercion reitit.http.interceptors.multipart/bytes-part]]] (testing coercion @@ -453,13 +457,16 @@ app :body)] (testing "multipart body" - (is (= {:requestBody {:content {"multipart/form-data" {:schema {:type "object" - :properties {"file" {:type "string" - :format "binary"}} - :required ["file"]}}}}} + (is (nil? (get-in spec [:paths "/upload" :post :parameters]))) + (is (= (merge {:type "object" + :properties {:file {:type "string" + :format "binary"}} + :required ["file"]} + (when-not (= #'spec/coercion coercion) + {:additionalProperties false})) (-> spec - (get-in [:paths "/upload" :post]) - #_normalize)))) + (get-in [:paths "/upload" :post :requestBody :content "multipart/form-data" :schema]) + normalize)))) (testing "spec is valid" (is (nil? (validate spec))))))))