A little bit on error messages:
I was playing around with specs on path-params, and I thought the :-
thingy was schema-only, so I made my thing like this
(context "/product/:id" []
:coercion :spec
:path-params [id ::id])
The error I get is either
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)
when I only evaluate this form, or
CompilerException java.lang.ClassCastException, compiling:(/Users/erik/Documents/telenordigital.com/di-data-inventory/src/data_inventory/handler.clj:225:9)
if I evaluate the whole api.
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.
As always, thanks for the great work!
Also, when using :spec
coercion, swagger fails with
500 : {"type":"unknown-exception","class":"java.lang.Exception"} <http://localhost:3000/swagger.json>
when at least one spec is missing.
so given something like
(s/def ::foo (s/keys :req-un [::bar]))
where ::bar
is not defined, swagger shows nothing at all.
just the exeption (which in the logs tells me that no spec is found for ::bar
This is somewhat unfortunate, as it makes gradual typing hard.
This may or may not be a design choice 🙂
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
could you write issues of these? and if you have time to fix ’em too, PRs welcome 🙂
and, actually, that swagger-gen should fail-early on the spec-tools.
should be easy to catch..
I’ll make issues for them for sure, compojure-api project?
1 to c-api, 2 to spec-tools, thanks!
Cool
Also, I hope this is the correct place to discuss these kinds of things?
yes, definetely
Hmm, Still some problems 😞
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))))
and ::id
is defined as (spec/def ::id pos-int?)
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)
I’ll take a look on that later today
Thanks!
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.
Ok, so a smaller repro here:
(context "/spec-test/:id" []
:coercion :spec
:path-params [id :- ::id]
(GET "/foo/" []
:return any?
(ok {:id 1 :name "foo" :date (DateTime.)})))
fails
whereas
(context "/spec-test" []
:coercion :spec
(GET "/:id/foo/" []
:path-params [id :- ::id]
:return any?
(ok {:id 1 :name "foo" :date (DateTime.)})))
works fine
(context "/spec-test/:id" []
:coercion :spec
(GET "/foo/" []
:path-params [id :- ::id]
:return any?
(ok {:id 1 :name "foo" :date (DateTime.)})))
seems to work as well, which is a workaround I can live with...
If you tell me which project this relates to, I'll be more than happy to file another issue 🙂
Another one
"pred": "clojure.lang.LazySeq@ba0ee888",
Should probably do a doall
or smthing to realize the lazy-sql which is the pred?