This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-15
Channels
- # beginners (97)
- # boot (54)
- # cider (13)
- # cljs-dev (3)
- # cljsrn (9)
- # clojure (64)
- # clojure-berlin (1)
- # clojure-brasil (119)
- # clojure-dev (3)
- # clojure-france (5)
- # clojure-greece (1)
- # clojure-italy (5)
- # clojure-madison (1)
- # clojure-russia (15)
- # clojure-spec (25)
- # clojure-uk (57)
- # clojurebridge (5)
- # clojurescript (45)
- # code-art (1)
- # community-development (17)
- # cursive (24)
- # datomic (83)
- # emacs (11)
- # fulcro (70)
- # hoplon (7)
- # immutant (3)
- # leiningen (19)
- # luminus (5)
- # lumo (25)
- # onyx (123)
- # other-languages (7)
- # pedestal (2)
- # re-frame (12)
- # ring (15)
- # ring-swagger (51)
- # shadow-cljs (89)
- # spacemacs (23)
- # sql (4)
- # unrepl (57)
- # utah-clojurians (1)
- # vim (1)
I was playing around with specs on path-params, and I thought the :-
thingy was schema-only, so I made my thing like this
CompilerException java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to clojure.lang.IObj, compiling:(/Users/erik/Documents/telenordigital.com/di-data-inventory/src/data_inventory/handler.clj:225:9)
CompilerException java.lang.ClassCastException, compiling:(/Users/erik/Documents/telenordigital.com/di-data-inventory/src/data_inventory/handler.clj:225:9)
I appreciate the fact that it might be hard getting good/descriptive error messages here, but I thought I’d post this as a bit of inspiration.
There was just today a discussion about this in the Clojure Google Group: https://groups.google.com/forum/m/#!topic/clojure/i8Rz-AnCoa8
I think both could be “fixed” on c-api side:
1) validate the plumbing.core/letk
syntax for bad syntax
2) validate that all s/keys
specs are fully set and fail nicely
So, in a nested context, where the outer context has default coercion, I have the following:
(context "/product/:id" []
:coercion :spec
:path-params [id :- ::id]
(GET "/foo" []
:return boolean?
:summary "foo"
(ok (reports/foo 1))))
This shows up fine in swagger, but when I press “try it out” i get the following stack-trace:
2017-11-15 14:14:47,930 [worker-4] ERROR compojure.api.exception - No implementation of method: :spec of protocol: #'schema.core/Schema found for class: clojure.lang.Keyword
java.lang.IllegalArgumentException: No implementation of method: :spec of protocol: #'schema.core/Schema found for class: clojure.lang.Keyword
at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:583)
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:575)
at schema.core$eval7391$fn__7403$G__7380__7408.invoke(core.clj:110)
at schema.coerce$eval8639$coercer__8644$fn__8645$fn__8646.invoke(coerce.clj:32)
at schema.spec.core$sub_checker$fn__7162.invoke(core.clj:92)
hey all - I have a question about using middleware to transform responses. I have code I want to apply to the response generated by all my handler functions, which brings the response into conformance with the schemas I've defined for them via compojure-api. It seems that the schema validation is happening before any of the middleware gets the response. Am I missing some way to configure middleware, or must I guarantee that anything returned by a handler is in the correct form?
my current workaround is a defhandler
macro which adds the transformation step to the end of all my handler functions. That's a little gruesome though.
(context "/spec-test/:id" []
:coercion :spec
:path-params [id :- ::id]
(GET "/foo/" []
:return any?
(ok {:id 1 :name "foo" :date (DateTime.)})))
(context "/spec-test" []
:coercion :spec
(GET "/:id/foo/" []
:path-params [id :- ::id]
:return any?
(ok {:id 1 :name "foo" :date (DateTime.)})))
(context "/spec-test/:id" []
:coercion :spec
(GET "/foo/" []
:path-params [id :- ::id]
:return any?
(ok {:id 1 :name "foo" :date (DateTime.)})))