mirror of
https://github.com/metosin/reitit.git
synced 2026-02-14 07:15:16 +00:00
Merge branch 'master' into frontend-fixes
This commit is contained in:
commit
845240d330
11 changed files with 232 additions and 56 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -12,13 +12,22 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino
|
||||||
|
|
||||||
[breakver]: https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md
|
[breakver]: https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md
|
||||||
|
|
||||||
## Unreleased
|
## UNRELEASED
|
||||||
|
|
||||||
### `reitit-frontend`
|
### `reitit-frontend`
|
||||||
|
|
||||||
- `reitit.frontend.easy/start!` now correctly removes old event listeners
|
- `reitit.frontend.easy/start!` now correctly removes old event listeners
|
||||||
when called repeatedly (e.g. with hot code reload workflow)
|
when called repeatedly (e.g. with hot code reload workflow)
|
||||||
([#438](https://github.com/metosin/reitit/pull/438))
|
([#438](https://github.com/metosin/reitit/pull/438))
|
||||||
|
* updated deps:
|
||||||
|
|
||||||
|
```clj
|
||||||
|
[metosin/malli "0.1.0"] is available but we use "0.0.1-20200924.063109-27"
|
||||||
|
[com.fasterxml.jackson.core/jackson-core "2.11.3"] is available but we use "2.11.2"
|
||||||
|
[com.fasterxml.jackson.core/jackson-databind "2.11.3"] is available but we use "2.11.2"
|
||||||
|
[expound "0.8.6"] is available but we use "0.8.5"
|
||||||
|
[ring/ring-core "1.8.2"] is available but we use "1.8.1"
|
||||||
|
```
|
||||||
|
|
||||||
## 0.5.6 (2020-09-26)
|
## 0.5.6 (2020-09-26)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ A fast data-driven router for Clojure(Script).
|
||||||
* Route [conflict resolution](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/basics/route-conflicts/)
|
* Route [conflict resolution](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/basics/route-conflicts/)
|
||||||
* First-class [route data](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/basics/route-data/)
|
* First-class [route data](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/basics/route-data/)
|
||||||
* Bi-directional routing
|
* Bi-directional routing
|
||||||
* [Pluggable coercion](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/coercion/coercion/) ([malli](https://github.com/metosin/malli), [schema](https://github.com/plumatic/schema) & [clojure.spec](https://clojure.org/about/spec))
|
* [Pluggable coercion](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/coercion/coercion-explained) ([malli](https://github.com/metosin/malli), [schema](https://github.com/plumatic/schema) & [clojure.spec](https://clojure.org/about/spec))
|
||||||
* Helpers for [ring](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/ring/ring/), [http](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/http/interceptors/), [pedestal](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/http/pedestal/) & [frontend](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/frontend/basics/)
|
* Helpers for [ring](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/ring/ring-router), [http](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/http/interceptors/), [pedestal](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/http/pedestal/) & [frontend](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/frontend/basics/)
|
||||||
* Friendly [Error Messages](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/basics/error-messages/)
|
* Friendly [Error Messages](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/basics/error-messages/)
|
||||||
* Extendable
|
* Extendable
|
||||||
* Modular
|
* Modular
|
||||||
* [Fast](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/performance/)
|
* [Fast](https://cljdoc.org/d/metosin/reitit/CURRENT/doc/misc/performance)
|
||||||
|
|
||||||
Presentations:
|
Presentations:
|
||||||
* [Reitit, The Ancient Art of Data-Driven](https://www.slideshare.net/mobile/metosin/reitit-clojurenorth-2019-141438093), Clojure/North 2019, [video](https://youtu.be/cSntRGAjPiM)
|
* [Reitit, The Ancient Art of Data-Driven](https://www.slideshare.net/mobile/metosin/reitit-clojurenorth-2019-141438093), Clojure/North 2019, [video](https://youtu.be/cSntRGAjPiM)
|
||||||
|
|
@ -151,6 +151,7 @@ All examples are in https://github.com/metosin/reitit/tree/master/examples
|
||||||
* [startrek-ui](https://git.sr.ht/~dharrigan/startrek-ui)
|
* [startrek-ui](https://git.sr.ht/~dharrigan/startrek-ui)
|
||||||
* https://www.learnreitit.com/
|
* https://www.learnreitit.com/
|
||||||
* Lipas, liikuntapalvelut: https://github.com/lipas-liikuntapaikat/lipas
|
* Lipas, liikuntapalvelut: https://github.com/lipas-liikuntapaikat/lipas
|
||||||
|
* Implementation of the Todo-Backend API spec, using Clojure, Ring/Reitit and next-jdbc: https://github.com/PrestanceDesign/todo-backend-clojure-reitit
|
||||||
|
|
||||||
## More info
|
## More info
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,16 @@
|
||||||
(defn- displace [x] (with-meta x {:displace true}))
|
(defn- displace [x] (with-meta x {:displace true}))
|
||||||
(defn- stripped [x] (select-keys x [:enter :leave :error]))
|
(defn- stripped [x] (select-keys x [:enter :leave :error]))
|
||||||
|
|
||||||
|
(defn- publish-swagger-data? [{:keys [form body]}]
|
||||||
|
(not (and (some? form)
|
||||||
|
(nil? body))))
|
||||||
|
|
||||||
|
(defn- swagger-data [parameters muuntaja]
|
||||||
|
(if (publish-swagger-data? parameters)
|
||||||
|
{:data {:swagger {:produces (displace (m/encodes muuntaja))
|
||||||
|
:consumes (displace (m/decodes muuntaja))}}}
|
||||||
|
{}))
|
||||||
|
|
||||||
(defn format-interceptor
|
(defn format-interceptor
|
||||||
"Interceptor for content-negotiation, request and response formatting.
|
"Interceptor for content-negotiation, request and response formatting.
|
||||||
|
|
||||||
|
|
@ -22,6 +32,8 @@
|
||||||
Encodes the response body using the `:muuntaja/response` key in request if the response
|
Encodes the response body using the `:muuntaja/response` key in request if the response
|
||||||
doesn't have `Content-Type` header already set.
|
doesn't have `Content-Type` header already set.
|
||||||
|
|
||||||
|
Swagger-data will be omitted when `:form`, but no `:body`, parameters are defined.
|
||||||
|
|
||||||
Optionally takes a default muuntaja instance as argument.
|
Optionally takes a default muuntaja instance as argument.
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
|
|
@ -32,12 +44,11 @@
|
||||||
([default-muuntaja]
|
([default-muuntaja]
|
||||||
{:name ::format
|
{:name ::format
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja parameters]} _]
|
||||||
(if-let [muuntaja (or muuntaja default-muuntaja)]
|
(if-let [muuntaja (or muuntaja default-muuntaja)]
|
||||||
(merge
|
(merge
|
||||||
(stripped (muuntaja.interceptor/format-interceptor muuntaja))
|
(stripped (muuntaja.interceptor/format-interceptor muuntaja))
|
||||||
{:data {:swagger {:produces (displace (m/encodes muuntaja))
|
(swagger-data parameters muuntaja))))}))
|
||||||
:consumes (displace (m/decodes muuntaja))}}})))}))
|
|
||||||
|
|
||||||
(defn format-negotiate-interceptor
|
(defn format-negotiate-interceptor
|
||||||
"Interceptor for content-negotiation.
|
"Interceptor for content-negotiation.
|
||||||
|
|
@ -66,6 +77,8 @@
|
||||||
Decodes the request body into `:body-params` using the `:muuntaja/request` key in request
|
Decodes the request body into `:body-params` using the `:muuntaja/request` key in request
|
||||||
if the `:body-params` doesn't already exist.
|
if the `:body-params` doesn't already exist.
|
||||||
|
|
||||||
|
Swagger-data will be omitted when `:form`, but no `:body`, parameters are defined.
|
||||||
|
|
||||||
Optionally takes a default muuntaja instance as argument.
|
Optionally takes a default muuntaja instance as argument.
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
|
|
@ -76,11 +89,12 @@
|
||||||
([default-muuntaja]
|
([default-muuntaja]
|
||||||
{:name ::format-request
|
{:name ::format-request
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja parameters]} _]
|
||||||
(if-let [muuntaja (or muuntaja default-muuntaja)]
|
(if-let [muuntaja (or muuntaja default-muuntaja)]
|
||||||
(merge
|
(merge
|
||||||
(stripped (muuntaja.interceptor/format-request-interceptor muuntaja))
|
(stripped (muuntaja.interceptor/format-request-interceptor muuntaja))
|
||||||
{:data {:swagger {:consumes (displace (m/decodes muuntaja))}}})))}))
|
(when (publish-swagger-data? parameters)
|
||||||
|
{:data {:swagger {:consumes (displace (m/decodes muuntaja))}}}))))}))
|
||||||
|
|
||||||
(defn format-response-interceptor
|
(defn format-response-interceptor
|
||||||
"Interceptor for response formatting.
|
"Interceptor for response formatting.
|
||||||
|
|
@ -88,6 +102,8 @@
|
||||||
Encodes the response body using the `:muuntaja/response` key in request if the response
|
Encodes the response body using the `:muuntaja/response` key in request if the response
|
||||||
doesn't have `Content-Type` header already set.
|
doesn't have `Content-Type` header already set.
|
||||||
|
|
||||||
|
Swagger-data will be omitted when `:form`, but no `:body`, parameters are defined.
|
||||||
|
|
||||||
Optionally takes a default muuntaja instance as argument.
|
Optionally takes a default muuntaja instance as argument.
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
|
|
@ -98,8 +114,9 @@
|
||||||
([default-muuntaja]
|
([default-muuntaja]
|
||||||
{:name ::format-response
|
{:name ::format-response
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja parameters]} _]
|
||||||
(if-let [muuntaja (or muuntaja default-muuntaja)]
|
(if-let [muuntaja (or muuntaja default-muuntaja)]
|
||||||
(merge
|
(merge
|
||||||
(stripped (muuntaja.interceptor/format-response-interceptor muuntaja))
|
(stripped (muuntaja.interceptor/format-response-interceptor muuntaja))
|
||||||
{:data {:swagger {:produces (displace (m/encodes muuntaja))}}})))}))
|
(when (publish-swagger-data? parameters)
|
||||||
|
{:data {:swagger {:produces (displace (m/encodes muuntaja))}}}))))}))
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
:params - a merged map of all types of parameter"
|
:params - a merged map of all types of parameter"
|
||||||
[]
|
[]
|
||||||
{:name ::parameters
|
{:name ::parameters
|
||||||
|
:compile (fn [{:keys [parameters]} _]
|
||||||
|
(if (and (some? (:form parameters)) (nil? (:body parameters)))
|
||||||
|
{:data {:swagger {:consumes ["application/x-www-form-urlencoded"]}}}
|
||||||
|
{}))
|
||||||
:enter (fn [ctx]
|
:enter (fn [ctx]
|
||||||
(let [request (:request ctx)]
|
(let [request (:request ctx)]
|
||||||
(assoc ctx :request (params/params-request request))))})
|
(assoc ctx :request (params/params-request request))))})
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,16 @@
|
||||||
|
|
||||||
(defn- displace [x] (with-meta x {:displace true}))
|
(defn- displace [x] (with-meta x {:displace true}))
|
||||||
|
|
||||||
|
(defn- publish-swagger-data? [{:keys [form body]}]
|
||||||
|
(not (and (some? form)
|
||||||
|
(nil? body))))
|
||||||
|
|
||||||
|
(defn- swagger-data [parameters muuntaja]
|
||||||
|
(if (publish-swagger-data? parameters)
|
||||||
|
{:data {:swagger {:produces (displace (m/encodes muuntaja))
|
||||||
|
:consumes (displace (m/decodes muuntaja))}}}
|
||||||
|
{}))
|
||||||
|
|
||||||
(def format-middleware
|
(def format-middleware
|
||||||
"Middleware for content-negotiation, request and response formatting.
|
"Middleware for content-negotiation, request and response formatting.
|
||||||
|
|
||||||
|
|
@ -21,16 +31,18 @@
|
||||||
Encodes the response body using the `:muuntaja/response` key in request if the response
|
Encodes the response body using the `:muuntaja/response` key in request if the response
|
||||||
doesn't have `Content-Type` header already set.
|
doesn't have `Content-Type` header already set.
|
||||||
|
|
||||||
|
Swagger-data will be omitted when `:form`, but no `:body`, parameters are defined.
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
| -------------|-------------|
|
| -------------|-------------|
|
||||||
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
||||||
{:name ::format
|
{:name ::format
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja parameters]} _]
|
||||||
(if muuntaja
|
(if muuntaja
|
||||||
{:data {:swagger {:produces (displace (m/encodes muuntaja))
|
(merge
|
||||||
:consumes (displace (m/decodes muuntaja))}}
|
(swagger-data parameters muuntaja)
|
||||||
:wrap #(muuntaja.middleware/wrap-format % muuntaja)}))})
|
{:wrap #(muuntaja.middleware/wrap-format % muuntaja)})))})
|
||||||
|
|
||||||
(def format-negotiate-middleware
|
(def format-negotiate-middleware
|
||||||
"Middleware for content-negotiation.
|
"Middleware for content-negotiation.
|
||||||
|
|
@ -54,15 +66,19 @@
|
||||||
Decodes the request body into `:body-params` using the `:muuntaja/request` key in request
|
Decodes the request body into `:body-params` using the `:muuntaja/request` key in request
|
||||||
if the `:body-params` doesn't already exist.
|
if the `:body-params` doesn't already exist.
|
||||||
|
|
||||||
|
Swagger-data will be omitted when `:form`, but no `:body`, parameters are defined.
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
| -------------|-------------|
|
| -------------|-------------|
|
||||||
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
||||||
{:name ::format-request
|
{:name ::format-request
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja parameters]} _]
|
||||||
(if muuntaja
|
(if muuntaja
|
||||||
{:data {:swagger {:consumes (displace (m/decodes muuntaja))}}
|
(merge
|
||||||
:wrap #(muuntaja.middleware/wrap-format-request % muuntaja)}))})
|
(when (publish-swagger-data? parameters)
|
||||||
|
{:data {:swagger {:consumes (displace (m/decodes muuntaja))}}})
|
||||||
|
{:wrap #(muuntaja.middleware/wrap-format-request % muuntaja)})))})
|
||||||
|
|
||||||
(def format-response-middleware
|
(def format-response-middleware
|
||||||
"Middleware for response formatting.
|
"Middleware for response formatting.
|
||||||
|
|
@ -70,12 +86,16 @@
|
||||||
Encodes the response body using the `:muuntaja/response` key in request if the response
|
Encodes the response body using the `:muuntaja/response` key in request if the response
|
||||||
doesn't have `Content-Type` header already set.
|
doesn't have `Content-Type` header already set.
|
||||||
|
|
||||||
|
Swagger-data will be omitted when `:form`, but no `:body`, parameters are defined.
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
| -------------|-------------|
|
| -------------|-------------|
|
||||||
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
||||||
{:name ::format-response
|
{:name ::format-response
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja parameters]} _]
|
||||||
(if muuntaja
|
(if muuntaja
|
||||||
{:data {:swagger {:produces (displace (m/encodes muuntaja))}}
|
(merge
|
||||||
:wrap #(muuntaja.middleware/wrap-format-response % muuntaja)}))})
|
(when (publish-swagger-data? parameters)
|
||||||
|
{:data {:swagger {:produces (displace (m/encodes muuntaja))}}})
|
||||||
|
{:wrap #(muuntaja.middleware/wrap-format-response % muuntaja)})))})
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,8 @@
|
||||||
:form-params - a map of parameters from the body
|
:form-params - a map of parameters from the body
|
||||||
:params - a merged map of all types of parameter"
|
:params - a merged map of all types of parameter"
|
||||||
{:name ::parameters
|
{:name ::parameters
|
||||||
|
:compile (fn [{:keys [parameters]} _]
|
||||||
|
(if (and (some? (:form parameters)) (nil? (:body parameters)))
|
||||||
|
{:data {:swagger {:consumes ["application/x-www-form-urlencoded"]}}}
|
||||||
|
{}))
|
||||||
:wrap params/wrap-params})
|
:wrap params/wrap-params})
|
||||||
|
|
|
||||||
22
project.clj
22
project.clj
|
|
@ -33,18 +33,18 @@
|
||||||
[metosin/muuntaja "0.6.7"]
|
[metosin/muuntaja "0.6.7"]
|
||||||
[metosin/jsonista "0.2.7"]
|
[metosin/jsonista "0.2.7"]
|
||||||
[metosin/sieppari "0.0.0-alpha13"]
|
[metosin/sieppari "0.0.0-alpha13"]
|
||||||
[metosin/malli "0.0.1-20200924.063109-27"]
|
[metosin/malli "0.1.0"]
|
||||||
|
|
||||||
;; https://clojureverse.org/t/depending-on-the-right-versions-of-jackson-libraries/5111
|
;; https://clojureverse.org/t/depending-on-the-right-versions-of-jackson-libraries/5111
|
||||||
[com.fasterxml.jackson.core/jackson-core "2.11.2"]
|
[com.fasterxml.jackson.core/jackson-core "2.11.3"]
|
||||||
[com.fasterxml.jackson.core/jackson-databind "2.11.2"]
|
[com.fasterxml.jackson.core/jackson-databind "2.11.3"]
|
||||||
|
|
||||||
[meta-merge "1.0.0"]
|
[meta-merge "1.0.0"]
|
||||||
[fipp "0.6.23" :exclusions [org.clojure/core.rrb-vector]]
|
[fipp "0.6.23" :exclusions [org.clojure/core.rrb-vector]]
|
||||||
[expound "0.8.5"]
|
[expound "0.8.6"]
|
||||||
[lambdaisland/deep-diff "0.0-47"]
|
[lambdaisland/deep-diff "0.0-47"]
|
||||||
[com.bhauman/spell-spec "0.1.2"]
|
[com.bhauman/spell-spec "0.1.2"]
|
||||||
[ring/ring-core "1.8.1"]
|
[ring/ring-core "1.8.2"]
|
||||||
|
|
||||||
[io.pedestal/pedestal.service "0.5.8"]]
|
[io.pedestal/pedestal.service "0.5.8"]]
|
||||||
|
|
||||||
|
|
@ -84,18 +84,18 @@
|
||||||
[metosin/schema-tools "0.12.2"]
|
[metosin/schema-tools "0.12.2"]
|
||||||
[metosin/spec-tools "0.10.4"]
|
[metosin/spec-tools "0.10.4"]
|
||||||
[metosin/muuntaja "0.6.7"]
|
[metosin/muuntaja "0.6.7"]
|
||||||
[metosin/sieppari]
|
[metosin/sieppari "0.0.0-alpha13"]
|
||||||
[metosin/jsonista "0.2.7"]
|
[metosin/jsonista "0.2.7"]
|
||||||
[metosin/malli]
|
[metosin/malli "0.1.0"]
|
||||||
[lambdaisland/deep-diff "0.0-47"]
|
[lambdaisland/deep-diff "0.0-47"]
|
||||||
[meta-merge "1.0.0"]
|
[meta-merge "1.0.0"]
|
||||||
[com.bhauman/spell-spec "0.1.2"]
|
[com.bhauman/spell-spec "0.1.2"]
|
||||||
[expound "0.8.5"]
|
[expound "0.8.6"]
|
||||||
[fipp "0.6.23"]
|
[fipp "0.6.23"]
|
||||||
|
|
||||||
[orchestra "2020.09.18-1"]
|
[orchestra "2020.09.18-1"]
|
||||||
|
|
||||||
[ring "1.8.1"]
|
[ring "1.8.2"]
|
||||||
[ikitommi/immutant-web "3.0.0-alpha1"]
|
[ikitommi/immutant-web "3.0.0-alpha1"]
|
||||||
[metosin/ring-http-response "0.9.1"]
|
[metosin/ring-http-response "0.9.1"]
|
||||||
[metosin/ring-swagger-ui "3.25.3"]
|
[metosin/ring-swagger-ui "3.25.3"]
|
||||||
|
|
@ -109,7 +109,7 @@
|
||||||
|
|
||||||
[org.clojure/core.async "1.3.610"]
|
[org.clojure/core.async "1.3.610"]
|
||||||
[manifold "0.1.8"]
|
[manifold "0.1.8"]
|
||||||
[funcool/promesa "5.1.0"]
|
[funcool/promesa "6.0.0"]
|
||||||
|
|
||||||
[com.clojure-goes-fast/clj-async-profiler "0.4.1"]
|
[com.clojure-goes-fast/clj-async-profiler "0.4.1"]
|
||||||
[ring-cors "0.1.13"]
|
[ring-cors "0.1.13"]
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
[calfpath "0.7.2"]
|
[calfpath "0.7.2"]
|
||||||
[org.clojure/core.async "1.3.610"]
|
[org.clojure/core.async "1.3.610"]
|
||||||
[manifold "0.1.8"]
|
[manifold "0.1.8"]
|
||||||
[funcool/promesa "5.1.0"]
|
[funcool/promesa "6.0.0"]
|
||||||
[metosin/sieppari]
|
[metosin/sieppari]
|
||||||
[yada "1.2.16"]
|
[yada "1.2.16"]
|
||||||
[aleph "0.4.6"]
|
[aleph "0.4.6"]
|
||||||
|
|
|
||||||
|
|
@ -36,20 +36,25 @@
|
||||||
["/just-edn"
|
["/just-edn"
|
||||||
{:muuntaja just-edn
|
{:muuntaja just-edn
|
||||||
:get identity}]
|
:get identity}]
|
||||||
|
["/form-params"
|
||||||
|
{:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
["/swagger.json"
|
["/swagger.json"
|
||||||
{:get {:no-doc true
|
{:get {:no-doc true
|
||||||
:handler (swagger/create-swagger-handler)}}]]
|
:handler (swagger/create-swagger-handler)}}]]
|
||||||
{:data {:muuntaja m/instance
|
{:data {:muuntaja m/instance
|
||||||
:interceptors [(muuntaja/format-interceptor)]}})
|
:interceptors [(muuntaja/format-interceptor)]}})
|
||||||
{:executor sieppari/executor})
|
{:executor sieppari/executor})
|
||||||
spec (fn [path]
|
spec (fn [method path]
|
||||||
(let [path (keyword path)]
|
(let [path (keyword path)]
|
||||||
(-> {:request-method :get :uri "/swagger.json"}
|
(-> {:request-method :get :uri "/swagger.json"}
|
||||||
(app) :body
|
(app) :body
|
||||||
(->> (m/decode m/instance "application/json"))
|
(->> (m/decode m/instance "application/json"))
|
||||||
:paths path :get)))
|
:paths path method)))
|
||||||
produces (comp set :produces spec)
|
produces (comp set :produces (partial spec :get))
|
||||||
consumes (comp set :consumes spec)]
|
consumes (comp set :consumes (partial spec :get))
|
||||||
|
post-produces (comp set :produces (partial spec :post))
|
||||||
|
post-consumes (comp set :consumes (partial spec :post))]
|
||||||
|
|
||||||
(testing "with defaults"
|
(testing "with defaults"
|
||||||
(let [path "/defaults"]
|
(let [path "/defaults"]
|
||||||
|
|
@ -85,7 +90,12 @@
|
||||||
(let [path "/just-edn"]
|
(let [path "/just-edn"]
|
||||||
(is (= #{"application/edn"}
|
(is (= #{"application/edn"}
|
||||||
(produces path)
|
(produces path)
|
||||||
(consumes path)))))))
|
(consumes path)))))
|
||||||
|
(testing "form parameters swagger-data"
|
||||||
|
(let [path "/form-params"]
|
||||||
|
(is (= #{}
|
||||||
|
(post-produces path)
|
||||||
|
(post-consumes path)))))))
|
||||||
|
|
||||||
(deftest muuntaja-swagger-parts-test
|
(deftest muuntaja-swagger-parts-test
|
||||||
(let [app (http/ring-handler
|
(let [app (http/ring-handler
|
||||||
|
|
@ -103,17 +113,35 @@
|
||||||
(muuntaja/format-response-interceptor)
|
(muuntaja/format-response-interceptor)
|
||||||
(muuntaja/format-request-interceptor)]
|
(muuntaja/format-request-interceptor)]
|
||||||
:get identity}]
|
:get identity}]
|
||||||
|
["/form-request"
|
||||||
|
{:interceptors [(muuntaja/format-negotiate-interceptor)
|
||||||
|
(muuntaja/format-request-interceptor)]
|
||||||
|
:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/form-response"
|
||||||
|
{:interceptors [(muuntaja/format-negotiate-interceptor)
|
||||||
|
(muuntaja/format-response-interceptor)]
|
||||||
|
:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/form-with-both"
|
||||||
|
{:interceptors [(muuntaja/format-negotiate-interceptor)
|
||||||
|
(muuntaja/format-response-interceptor)
|
||||||
|
(muuntaja/format-request-interceptor)]
|
||||||
|
:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
|
||||||
["/swagger.json"
|
["/swagger.json"
|
||||||
{:get {:no-doc true
|
{:get {:no-doc true
|
||||||
:handler (swagger/create-swagger-handler)}}]]
|
:handler (swagger/create-swagger-handler)}}]]
|
||||||
{:data {:muuntaja m/instance}})
|
{:data {:muuntaja m/instance}})
|
||||||
{:executor sieppari/executor})
|
{:executor sieppari/executor})
|
||||||
spec (fn [path]
|
spec (fn [method path]
|
||||||
(-> {:request-method :get :uri "/swagger.json"}
|
(-> {:request-method :get :uri "/swagger.json"}
|
||||||
(app) :body :paths (get path) :get))
|
(app) :body :paths (get path) method))
|
||||||
produces (comp :produces spec)
|
produces (comp :produces (partial spec :get))
|
||||||
consumes (comp :consumes spec)]
|
consumes (comp :consumes (partial spec :get))
|
||||||
|
post-produces (comp :produces (partial spec :post))
|
||||||
|
post-consumes (comp :consumes (partial spec :post))]
|
||||||
|
|
||||||
(testing "just request formatting"
|
(testing "just request formatting"
|
||||||
(let [path "/request"]
|
(let [path "/request"]
|
||||||
|
|
@ -133,7 +161,7 @@
|
||||||
(produces path)))
|
(produces path)))
|
||||||
(is (nil? (consumes path)))))
|
(is (nil? (consumes path)))))
|
||||||
|
|
||||||
(testing "just response formatting"
|
(testing "request and response formatting"
|
||||||
(let [path "/both"]
|
(let [path "/both"]
|
||||||
(is (= #{"application/json"
|
(is (= #{"application/json"
|
||||||
"application/transit+msgpack"
|
"application/transit+msgpack"
|
||||||
|
|
@ -144,4 +172,16 @@
|
||||||
"application/transit+msgpack"
|
"application/transit+msgpack"
|
||||||
"application/transit+json"
|
"application/transit+json"
|
||||||
"application/edn"}
|
"application/edn"}
|
||||||
(consumes path)))))))
|
(consumes path)))))
|
||||||
|
(testing "just request formatting for form params"
|
||||||
|
(let [path "/form-request"]
|
||||||
|
(is (nil? (post-produces path)))
|
||||||
|
(is (nil? (post-consumes path)))))
|
||||||
|
(testing "just response formatting for form params"
|
||||||
|
(let [path "/form-response"]
|
||||||
|
(is (nil? (post-produces path)))
|
||||||
|
(is (nil? (post-consumes path)))))
|
||||||
|
(testing "just request formatting for form params"
|
||||||
|
(let [path "/form-with-both"]
|
||||||
|
(is (nil? (post-produces path)))
|
||||||
|
(is (nil? (post-consumes path)))))))
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
(:require [clojure.test :refer [deftest testing is]]
|
(:require [clojure.test :refer [deftest testing is]]
|
||||||
[reitit.http.interceptors.parameters :as parameters]
|
[reitit.http.interceptors.parameters :as parameters]
|
||||||
[reitit.http :as http]
|
[reitit.http :as http]
|
||||||
[reitit.interceptor.sieppari :as sieppari]))
|
[reitit.interceptor.sieppari :as sieppari]
|
||||||
|
[reitit.swagger :as swagger]))
|
||||||
|
|
||||||
(deftest parameters-test
|
(deftest parameters-test
|
||||||
(let [app (http/ring-handler
|
(let [app (http/ring-handler
|
||||||
|
|
@ -15,3 +16,23 @@
|
||||||
(app {:request-method :get
|
(app {:request-method :get
|
||||||
:uri "/ping"
|
:uri "/ping"
|
||||||
:query-string "kikka=kukka"})))))
|
:query-string "kikka=kukka"})))))
|
||||||
|
|
||||||
|
(deftest parameters-swagger-test
|
||||||
|
(let [app (http/ring-handler
|
||||||
|
(http/router
|
||||||
|
[["/form-params" {:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/body-params" {:post {:parameters {:body {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/swagger.json" {:get {:no-doc true
|
||||||
|
:handler (swagger/create-swagger-handler)}}]]
|
||||||
|
{:data {:interceptors [(parameters/parameters-interceptor)]}})
|
||||||
|
{:executor sieppari/executor})
|
||||||
|
spec (fn [path]
|
||||||
|
(-> {:request-method :get :uri "/swagger.json"}
|
||||||
|
app
|
||||||
|
(get-in [:body :paths path :post])))]
|
||||||
|
(testing "with form parameters"
|
||||||
|
(is (= ["application/x-www-form-urlencoded"] (:consumes (spec "/form-params")))))
|
||||||
|
(testing "with body parameters"
|
||||||
|
(is (= nil (:consumes (spec "/body-params")))))))
|
||||||
|
|
|
||||||
|
|
@ -34,19 +34,24 @@
|
||||||
["/just-edn"
|
["/just-edn"
|
||||||
{:muuntaja just-edn
|
{:muuntaja just-edn
|
||||||
:get identity}]
|
:get identity}]
|
||||||
|
["/form-params"
|
||||||
|
{:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
["/swagger.json"
|
["/swagger.json"
|
||||||
{:get {:no-doc true
|
{:get {:no-doc true
|
||||||
:handler (swagger/create-swagger-handler)}}]]
|
:handler (swagger/create-swagger-handler)}}]]
|
||||||
{:data {:muuntaja m/instance
|
{:data {:muuntaja m/instance
|
||||||
:middleware [muuntaja/format-middleware]}}))
|
:middleware [muuntaja/format-middleware]}}))
|
||||||
spec (fn [path]
|
spec (fn [method path]
|
||||||
(let [path (keyword path)]
|
(let [path (keyword path)]
|
||||||
(-> {:request-method :get :uri "/swagger.json"}
|
(-> {:request-method :get :uri "/swagger.json"}
|
||||||
(app) :body
|
(app) :body
|
||||||
(->> (m/decode m/instance "application/json"))
|
(->> (m/decode m/instance "application/json"))
|
||||||
:paths path :get)))
|
:paths path method)))
|
||||||
produces (comp set :produces spec)
|
produces (comp set :produces (partial spec :get))
|
||||||
consumes (comp set :consumes spec)]
|
consumes (comp set :consumes (partial spec :get))
|
||||||
|
post-produces (comp set :produces (partial spec :post))
|
||||||
|
post-consumes (comp set :consumes (partial spec :post))]
|
||||||
|
|
||||||
(testing "with defaults"
|
(testing "with defaults"
|
||||||
(let [path "/defaults"]
|
(let [path "/defaults"]
|
||||||
|
|
@ -82,7 +87,12 @@
|
||||||
(let [path "/just-edn"]
|
(let [path "/just-edn"]
|
||||||
(is (= #{"application/edn"}
|
(is (= #{"application/edn"}
|
||||||
(produces path)
|
(produces path)
|
||||||
(consumes path)))))))
|
(consumes path)))))
|
||||||
|
(testing "form parameters swagger-data"
|
||||||
|
(let [path "/form-params"]
|
||||||
|
(is (= #{}
|
||||||
|
(post-produces path)
|
||||||
|
(post-consumes path)))))))
|
||||||
|
|
||||||
(deftest muuntaja-swagger-parts-test
|
(deftest muuntaja-swagger-parts-test
|
||||||
(let [app (ring/ring-handler
|
(let [app (ring/ring-handler
|
||||||
|
|
@ -100,16 +110,34 @@
|
||||||
muuntaja/format-response-middleware
|
muuntaja/format-response-middleware
|
||||||
muuntaja/format-request-middleware]
|
muuntaja/format-request-middleware]
|
||||||
:get identity}]
|
:get identity}]
|
||||||
|
["/form-request"
|
||||||
|
{:middleware [muuntaja/format-negotiate-middleware
|
||||||
|
muuntaja/format-request-middleware]
|
||||||
|
:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/form-response"
|
||||||
|
{:middleware [muuntaja/format-negotiate-middleware
|
||||||
|
muuntaja/format-response-middleware]
|
||||||
|
:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/form-with-both"
|
||||||
|
{:middleware [muuntaja/format-negotiate-middleware
|
||||||
|
muuntaja/format-response-middleware
|
||||||
|
muuntaja/format-request-middleware]
|
||||||
|
:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
|
||||||
["/swagger.json"
|
["/swagger.json"
|
||||||
{:get {:no-doc true
|
{:get {:no-doc true
|
||||||
:handler (swagger/create-swagger-handler)}}]]
|
:handler (swagger/create-swagger-handler)}}]]
|
||||||
{:data {:muuntaja m/instance}}))
|
{:data {:muuntaja m/instance}}))
|
||||||
spec (fn [path]
|
spec (fn [method path]
|
||||||
(-> {:request-method :get :uri "/swagger.json"}
|
(-> {:request-method :get :uri "/swagger.json"}
|
||||||
(app) :body :paths (get path) :get))
|
(app) :body :paths (get path) method))
|
||||||
produces (comp :produces spec)
|
produces (comp :produces (partial spec :get))
|
||||||
consumes (comp :consumes spec)]
|
consumes (comp :consumes (partial spec :get))
|
||||||
|
post-produces (comp :produces (partial spec :post))
|
||||||
|
post-consumes (comp :consumes (partial spec :post))]
|
||||||
|
|
||||||
(testing "just request formatting"
|
(testing "just request formatting"
|
||||||
(let [path "/request"]
|
(let [path "/request"]
|
||||||
|
|
@ -129,7 +157,7 @@
|
||||||
(produces path)))
|
(produces path)))
|
||||||
(is (nil? (consumes path)))))
|
(is (nil? (consumes path)))))
|
||||||
|
|
||||||
(testing "just response formatting"
|
(testing "request and response formatting"
|
||||||
(let [path "/both"]
|
(let [path "/both"]
|
||||||
(is (= #{"application/json"
|
(is (= #{"application/json"
|
||||||
"application/transit+msgpack"
|
"application/transit+msgpack"
|
||||||
|
|
@ -140,4 +168,16 @@
|
||||||
"application/transit+msgpack"
|
"application/transit+msgpack"
|
||||||
"application/transit+json"
|
"application/transit+json"
|
||||||
"application/edn"}
|
"application/edn"}
|
||||||
(consumes path)))))))
|
(consumes path)))))
|
||||||
|
(testing "just request formatting for form params"
|
||||||
|
(let [path "/form-request"]
|
||||||
|
(is (nil? (post-produces path)))
|
||||||
|
(is (nil? (post-consumes path)))))
|
||||||
|
(testing "just response formatting for form params"
|
||||||
|
(let [path "/form-response"]
|
||||||
|
(is (nil? (post-produces path)))
|
||||||
|
(is (nil? (post-consumes path)))))
|
||||||
|
(testing "just request formatting for form params"
|
||||||
|
(let [path "/form-with-both"]
|
||||||
|
(is (nil? (post-produces path)))
|
||||||
|
(is (nil? (post-consumes path)))))))
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
(ns reitit.ring.middleware.parameters-test
|
(ns reitit.ring.middleware.parameters-test
|
||||||
(:require [clojure.test :refer [deftest testing is]]
|
(:require [clojure.test :refer [deftest testing is]]
|
||||||
[reitit.ring.middleware.parameters :as parameters]
|
[reitit.ring.middleware.parameters :as parameters]
|
||||||
[reitit.ring :as ring]))
|
[reitit.ring :as ring]
|
||||||
|
[reitit.swagger :as swagger]))
|
||||||
|
|
||||||
(deftest parameters-test
|
(deftest parameters-test
|
||||||
(let [app (ring/ring-handler
|
(let [app (ring/ring-handler
|
||||||
|
|
@ -13,3 +14,22 @@
|
||||||
(app {:request-method :get
|
(app {:request-method :get
|
||||||
:uri "/ping"
|
:uri "/ping"
|
||||||
:query-string "kikka=kukka"})))))
|
:query-string "kikka=kukka"})))))
|
||||||
|
|
||||||
|
(deftest parameters-swagger-test
|
||||||
|
(let [app (ring/ring-handler
|
||||||
|
(ring/router
|
||||||
|
[["/form-params" {:post {:parameters {:form {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/body-params" {:post {:parameters {:body {:x string?}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/swagger.json" {:get {:no-doc true
|
||||||
|
:handler (swagger/create-swagger-handler)}}]]
|
||||||
|
{:data {:middleware [parameters/parameters-middleware]}}))
|
||||||
|
spec (fn [path]
|
||||||
|
(-> {:request-method :get :uri "/swagger.json"}
|
||||||
|
app
|
||||||
|
(get-in [:body :paths path :post])))]
|
||||||
|
(testing "with form parameters"
|
||||||
|
(is (= ["application/x-www-form-urlencoded"] (:consumes (spec "/form-params")))))
|
||||||
|
(testing "with body parameters"
|
||||||
|
(is (= nil (:consumes (spec "/body-params")))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue