Created
March 17, 2020 23:11
-
-
Save marrs/bded1dfa0b97893610b48b181b6fb50a to your computer and use it in GitHub Desktop.
Reproducible reitit bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject ring-example "0.1.0-SNAPSHOT" | |
:description "Reitit Ring App with Swagger" | |
:dependencies [ | |
[org.clojure/clojure "1.10.0"] | |
[ring/ring-jetty-adapter "1.7.1"] | |
[ring/ring-devel "1.8.0"] | |
[metosin/reitit "0.4.2"] | |
] | |
:repl-options {:init-ns server} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns server | |
(:require [reitit.ring :as ring] | |
[reitit.swagger :as swagger] | |
[reitit.swagger-ui :as swagger-ui] | |
[reitit.ring.coercion :as ring-coercion] | |
[reitit.dev.pretty :as pretty] | |
[reitit.ring.middleware.muuntaja :as muuntaja] | |
[reitit.ring.middleware.exception :as exception] | |
[reitit.ring.middleware.multipart :as multipart] | |
[reitit.ring.middleware.parameters :as parameters] | |
[reitit.coercion.schema] | |
[reitit.coercion :as coercion] | |
[schema.core :as s] | |
[reitit.core :as r] | |
[ring.adapter.jetty :as jetty] | |
[muuntaja.core :as m] | |
[ring.middleware.reload :refer [wrap-reload]] | |
)) | |
(def router-dummy (ring/router [] {:data {}})) | |
(defn merge-routers [& routers] | |
(r/router | |
(apply merge (map r/routes routers)) | |
(apply merge (map r/options routers)))) | |
(defn test-route [path summary body-schema body-payload] | |
[ path { | |
:post { | |
:summary summary | |
:parameters { :body { :a s/Str } } | |
:responses { | |
200 {:body body-schema} | |
} | |
:handler (fn [x] { | |
:status 200 | |
:body body-payload | |
}) | |
} | |
}] | |
) | |
(def router-api | |
(ring/router [ | |
["/swagger.json" { | |
:get {:no-doc true | |
:swagger {:info {:title "my-api" | |
:description "with reitit-ring"}} | |
:handler (swagger/create-swagger-handler)}}] | |
(test-route "/success" | |
"Correctly Responds with 200" {:success s/Bool} {:success true}) | |
(test-route "/failure" | |
"Incorrectly Responds with 400, indiating request body as source of error" s/Bool true) | |
] | |
{ | |
:compile coercion/compile-request-coercers | |
:data { | |
:coercion reitit.coercion.schema/coercion | |
:muuntaja m/instance | |
:middleware [ | |
muuntaja/format-negotiate-middleware ;; content-negotiation | |
muuntaja/format-response-middleware ;; encoding response body | |
muuntaja/format-request-middleware ;; decoding request body | |
exception/exception-middleware ;; exception handling XXX Can hide error messages! | |
ring-coercion/coerce-response-middleware ;; coercing response bodys | |
ring-coercion/coerce-request-middleware ;; coercing request parameters | |
] | |
} | |
}) | |
) | |
(def app | |
(ring/ring-handler | |
(merge-routers router-api router-dummy) | |
(ring/routes | |
(swagger-ui/create-swagger-ui-handler | |
{:path "/" | |
:config {:validatorUrl nil | |
:operationsSorter "alpha"}}) | |
(ring/create-default-handler)))) | |
(def reloadable-app | |
(wrap-reload #'app)) | |
(defn start [] | |
(jetty/run-jetty #'reloadable-app {:port 3000, :join? false}) | |
(println "server running in port 3000")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment