mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
feat: openapi3 multipart support for malli
This commit is contained in:
parent
f322597c04
commit
1c65f533cf
2 changed files with 24 additions and 9 deletions
|
|
@ -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 {}
|
||||
|
|
|
|||
|
|
@ -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))))))))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue