feat: route data validation for per-content-type coercions

This commit is contained in:
Joel Kaasinen 2023-03-08 14:20:37 +02:00
parent 9ae3cd0824
commit 50c1af9a5b
3 changed files with 14 additions and 3 deletions

View file

@ -82,14 +82,21 @@
(s/def :reitit.core.coercion/model any?)
(s/def :reitit.core.coercion/content
(s/map-of string? :reitit.core.coercion/model))
(s/def :reitit.core.coercion/query :reitit.core.coercion/model)
(s/def :reitit.core.coercion/body :reitit.core.coercion/model)
(s/def :reitit.core.coercion/request
(s/keys :opt-un [:reitit.core.coercion/content
:reitit.core.coercion/body]))
(s/def :reitit.core.coercion/form :reitit.core.coercion/model)
(s/def :reitit.core.coercion/header :reitit.core.coercion/model)
(s/def :reitit.core.coercion/path :reitit.core.coercion/model)
(s/def :reitit.core.coercion/parameters
(s/keys :opt-un [:reitit.core.coercion/query
:reitit.core.coercion/body
:reitit.core.coercion/request
:reitit.core.coercion/form
:reitit.core.coercion/header
:reitit.core.coercion/path]))
@ -103,7 +110,8 @@
(s/def :reitit.core.coercion/body any?)
(s/def :reitit.core.coercion/description string?)
(s/def :reitit.core.coercion/response
(s/keys :opt-un [:reitit.core.coercion/body
(s/keys :opt-un [:reitit.core.coercion/content
:reitit.core.coercion/body
:reitit.core.coercion/description]))
(s/def :reitit.core.coercion/responses
(s/map-of :reitit.core.coercion/status :reitit.core.coercion/response))

View file

@ -12,9 +12,10 @@
(s/def ::tags (s/coll-of (s/or :keyword keyword? :string string?)))
(s/def ::summary string?)
(s/def ::description string?)
(s/def ::content-types (s/coll-of string?))
(s/def ::openapi (s/keys :opt-un [::id]))
(s/def ::spec (s/keys :opt-un [::openapi ::no-doc ::tags ::summary ::description]))
(s/def ::spec (s/keys :opt-un [::openapi ::no-doc ::tags ::summary ::description ::content-types]))
(def openapi-feature
"Feature for handling openapi-documentation for routes.

View file

@ -11,6 +11,7 @@
[reitit.coercion.spec :as spec]
[reitit.core :as r]
[reitit.ring :as ring]
[reitit.ring.spec]
[reitit.ring.coercion :as rrc]
[schema.core :as s]
[clojure.spec.alpha]
@ -618,7 +619,8 @@
:handler (fn [req]
{:status 200
:body (-> req :parameters :request)})}}]]
{:data {:middleware [rrc/coerce-request-middleware
{:validate reitit.ring.spec/validate
:data {:middleware [rrc/coerce-request-middleware
rrc/coerce-response-middleware]
:coercion @coercion}}))
call (fn [request]