feat: openapi3 multipart support for schema

This commit is contained in:
Joel Kaasinen 2023-03-15 14:22:21 +02:00
parent 60f53d7e7c
commit acbcec1ed9
2 changed files with 11 additions and 2 deletions

View file

@ -70,7 +70,7 @@
(update $ :schema #(coercion/-compile-model this % nil)) (update $ :schema #(coercion/-compile-model this % nil))
$))]))}))) $))]))})))
:openapi (merge :openapi (merge
(when (seq (dissoc parameters :body :request)) (when (seq (dissoc parameters :body :request :multipart))
(openapi/openapi-spec {::openapi/parameters (openapi/openapi-spec {::openapi/parameters
(into (into
(empty parameters) (empty parameters)
@ -85,6 +85,10 @@
(when-let [default (get-in parameters [:request :body])] (when-let [default (get-in parameters [:request :body])]
(zipmap content-types (repeat default))) (zipmap content-types (repeat default)))
(:content (:request parameters)))})}) (:content (:request parameters)))})})
(when (:multipart parameters)
{:requestBody
(openapi/openapi-spec
{::openapi/content {"multipart/form-data" (:multipart parameters)}})})
(when responses (when responses
{:responses {:responses
(into (into

View file

@ -15,6 +15,7 @@
[reitit.ring.coercion :as rrc] [reitit.ring.coercion :as rrc]
[reitit.swagger-ui :as swagger-ui] [reitit.swagger-ui :as swagger-ui]
[schema.core :as s] [schema.core :as s]
[schema-tools.core]
[spec-tools.data-spec :as ds])) [spec-tools.data-spec :as ds]))
(defn validate (defn validate
@ -437,7 +438,11 @@
[:filename :string] [:filename :string]
[:content-type :string] [:content-type :string]
[:bytes :int]]] [:bytes :int]]]
#_[#'schema/coercion (fn [nom] {nom s/Str})] [#'schema/coercion (schema-tools.core/schema {:filename s/Str
:content-type s/Str
:bytes s/Num}
{:openapi {:type "string"
:format "binary"}})]
[#'spec/coercion reitit.http.interceptors.multipart/bytes-part]]] [#'spec/coercion reitit.http.interceptors.multipart/bytes-part]]]
(testing coercion (testing coercion
(let [app (ring/ring-handler (let [app (ring/ring-handler