2017-12-03 15:43:40 +00:00
|
|
|
(ns example.spec
|
|
|
|
|
(:require [clojure.spec.alpha :as s]
|
|
|
|
|
[spec-tools.spec :as spec]
|
2018-01-01 20:10:15 +00:00
|
|
|
[reitit.coercion.spec]))
|
2017-12-03 15:43:40 +00:00
|
|
|
|
|
|
|
|
;; wrap into Spec Records to enable runtime conforming
|
|
|
|
|
(s/def ::x spec/int?)
|
|
|
|
|
(s/def ::y spec/int?)
|
|
|
|
|
(s/def ::total spec/int?)
|
|
|
|
|
|
|
|
|
|
(def routes
|
2018-01-01 20:10:15 +00:00
|
|
|
["/spec" {:coercion reitit.coercion.spec/coercion}
|
2017-12-03 15:43:40 +00:00
|
|
|
["/plus" {:name ::plus
|
2018-01-01 20:10:49 +00:00
|
|
|
:responses {200 {:body (s/keys :req-un [::total])}}
|
2017-12-03 15:43:40 +00:00
|
|
|
:get {:summary "plus with query-params"
|
|
|
|
|
:parameters {:query (s/keys :req-un [::x ::y])}
|
|
|
|
|
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
|
|
|
|
{:status 200
|
|
|
|
|
:body {:total (+ x y)}})}
|
|
|
|
|
:post {:summary "plus with body-params"
|
|
|
|
|
:parameters {:body (s/keys :req-un [::x ::y])}
|
|
|
|
|
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
|
|
|
|
{:status 200
|
|
|
|
|
:body {:total (+ x y)}})}}]])
|