This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-31
Channels
- # aws (2)
- # beginners (101)
- # cider (8)
- # clara (8)
- # cljs-dev (3)
- # cljsrn (17)
- # clojars (2)
- # clojure (67)
- # clojure-austin (2)
- # clojure-finland (1)
- # clojure-france (5)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-russia (2)
- # clojure-serbia (1)
- # clojure-spec (72)
- # clojure-uk (112)
- # clojurescript (92)
- # core-async (74)
- # core-typed (2)
- # cursive (8)
- # datomic (2)
- # duct (5)
- # emacs (35)
- # events (11)
- # fulcro (32)
- # instaparse (9)
- # jobs (1)
- # luminus (1)
- # lumo (3)
- # off-topic (118)
- # om (2)
- # onyx (10)
- # pedestal (5)
- # re-frame (21)
- # reagent (48)
- # reitit (40)
- # ring (12)
- # shadow-cljs (113)
- # spacemacs (21)
- # tools-deps (47)
Is someone using the route-data validation? Checked how to integrate spec-tools + spell-spec together, planning to port all middleware, interceptor and feature specs into data-specs and get spell-spec for free. Not 100% it works, but will try.
I think there could be reitit-dev
module, with expound and spell-spec pre-integrated. could contains a function to wrap any router
, injecting the needed options to get the data validation enabled easily. and maybe serve the routes to a dev-ui/visualization.
I'm struggling with another spec validation problem. The first request sent that routes via reitit fails the :ring/request
spec from ring-spec
because the request map that gets passed to it contains the keys :body
and :query-string
with nil
values, but these keys are not nilable
. Any idea how these keys find their way into the request map? This doesn't seem to happen if the requests are not routed via reitit - my top-level handler is created using (rr/ring-handler (rr/router ...))
Here's the error (via expound):
Call to #'hanabi.web/initialise did not conform to spec:
web.clj:181
-- Spec failed --------------------
Function arguments
({:reitit.core/match ...,
:reitit.core/router ...,
:remote-addr ...,
:params ...,
:headers ...,
:async-channel ...,
:server-port ...,
:content-length ...,
:form-params ...,
:websocket? ...,
:web/session ...,
:query-params ...,
:content-type ...,
:character-encoding ...,
:uri ...,
:server-name ...,
:query-string ...,
:path-params ...,
:body nil,
^^^
:scheme ...,
:request-method ...})
should satisfy
#object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x765709fc "clojure.spec.alpha$regex_spec_impl$reify__2436@765709fc"]
-- Relevant specs -------
:ring.request/body:
:clojure.spec.alpha/unknown
:ring/request:
(clojure.spec.alpha/keys
:req-un
[:ring.request/server-port
:ring.request/server-name
:ring.request/remote-addr
:ring.request/uri
:ring.request/scheme
:ring.request/protocol
:ring.request/headers
:ring.request/request-method]
:opt-un
[:ring.request/query-string :ring.request/body])
:web.ring/request:
(clojure.spec.alpha/merge
:ring/request
(clojure.spec.alpha/keys
:req
[:web/session]
:req-un
[:web.ring.request/edn-params]))
-- Spec failed --------------------
Function arguments
({:reitit.core/match ...,
:reitit.core/router ...,
:remote-addr ...,
:params ...,
:headers ...,
:async-channel ...,
:server-port ...,
:content-length ...,
:form-params ...,
:websocket? ...,
:web/session ...,
:query-params ...,
:content-type ...,
:character-encoding ...,
:uri ...,
:server-name ...,
:query-string nil,
^^^
:path-params ...,
:body ...,
:scheme ...,
:request-method ...})
should satisfy
#object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x765709fc "clojure.spec.alpha$regex_spec_impl$reify__2436@765709fc"]
-- Relevant specs -------
:ring.request/query-string:
:clojure.spec.alpha/unknown
:ring/request:
(clojure.spec.alpha/keys
:req-un
[:ring.request/server-port
:ring.request/server-name
:ring.request/remote-addr
:ring.request/uri
:ring.request/scheme
:ring.request/protocol
:ring.request/headers
:ring.request/request-method]
:opt-un
[:ring.request/query-string :ring.request/body])
:web.ring/request:
(clojure.spec.alpha/merge
:ring/request
(clojure.spec.alpha/keys
:req
[:web/session]
:req-un
[:web.ring.request/edn-params]))
-------------------------
Detected 2 errors
query-string
is parsed by a external middleware, like ring.middleware.params/wrap-params
, :body is nil
after it’s consumed by the body-formatter like muuntaja.middleware/wrap-format
.
well, the other one if from ring itself, so ring doesn’t seem to be compatible with the ring-spec?
if the value is nil
, then the key can be removed from the request map to keep it spec-compliant
if the body is parsed, the stream is read. Now muuntaja put’s nil in there, could keep the empty stream
actually, if you could ask in #ring or via issues. I can fix muuntaja, but need to know how.
hmm… can’t see how the :query-params
could be nil
: https://github.com/ring-clojure/ring/blob/1.6.1/ring-core/src/ring/middleware/params.clj#L7-L19
it might set the :query-string
to nil
if it’s not set. If you print out the request coming from the adapter and see if it’s nil
.
I would allow nil
as it’s more idiomatic Clojure. easy to pipe logic for “there is no query-string set”.
{:body #object[io.undertow.io.UndertowInputStream 0x44f9e7f5 "io.undertow.io.UndertowInputStream@44f9e7f5"],
:character-encoding "ISO-8859-1", :content-length -1, :content-type nil, :context "", :handler-type :undertow,
:headers {"accept" "image/webp,image/apng,image/*,*/*;q=0.8", "accept-encoding" "gzip, deflate, br",
"accept-language" "en-US,en;q=0.9,fi-FI;q=0.8,fi;q=0.7", "connection" "keep-alive", "dnt" "1",
"host" "localhost:9999", "referer" " ",
"user-agent" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"},
:path-info "/favicon.ico", :query-string nil, :remote-addr "127.0.0.1", :request-method :get, :scheme :http,
:server-exchange #object[io.undertow.server.HttpServerExchange 0x4a3e10c2 "HttpServerExchange{ GET /favicon.ico request {Connection=[keep-alive], Accept=[image/webp,image/apng,image/*,*/*;q=0.8], Accept-Language=[en-US,en;q=0.9,fi-FI;q=0.8,fi;q=0.7], Accept-Encoding=[gzip, deflate, br], DNT=[1], User-Agent=[Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36], Referer=[ ], Host=[localhost:9999]} response {Server=[undertow]}}"],
:server-name "localhost", :server-port 9999, :ssl-client-cert nil, :uri "/favicon.ico", :muuntaja/request nil,
:muuntaja/response #FormatAndCharset{:charset "utf-8",
:format "application/json"}}