Trying to use existing specs to spec a swagger route using compojure-api, I have a function that takes a function and returns the arguments in a vector separated by :-
when I try and use this in body-params, I get a plumbing error
Syntax error macroexpanding POST at (routes.clj:90:7).
Binding is not valid, please refer to <https://github.com/plumatic/plumbing/tree/master/src/plumbing/fnk#fnk-syntax>
for more information.
binding: (sw/params (quote my-param-spec))
is there anyway to generate the specs from existing specs, or do they need to be manually copied?
Hi.
Do you know, how can I customise Example value
in swagger, using :coercion :spec
. I was hoping to generate that value out of spec directly (I have proper generators attached to my specs). Using compojure-api
2.0.0-alpha29
. I wonder if that's even possible, if not I'll hardcode that. Thanks!
Just for reference, you can achieve that with spec-tools
, specifying json-schema/example
with the spec.
https://github.com/metosin/spec-tools/blob/master/docs/01_coercion.md#spec-based-transformations
Is it possible to programatically generate a URL for a route, given the necessary blanks for the path etc. parameters? Maybe I missed this in the docs.
@jonathanj see https://github.com/metosin/compojure-api/blob/master/src/compojure/api/routes.clj#L226-L242
@lumpy clojure.spec is not the best at creating specs at runtime - it has been out of scope in Spec1. There is a Spec2 on the making which should fix this. With Spec1, you usually need macros or eval to compose things. But if you can make the specs work in the repl, they should work with c-api.
C-api builds on top of (Compojure) macros, so it's not always easy to understand what happens when (macro compilation time, route creation time, request processing time).
Best way to debug the endpoints is to run macroexpand-1
on the route. E.g.
(macroexpand-1
`(GET "/ping" []
:body [body (s/keys :req-un [::x ::y])]
(ok body)))
also, just evaluating the GET
form on the repl shows the internal Route
definition.
I think c & c-api have one of the most terse/powerful route syntax out there. But it's not the simplest one. For simple (but much more verbose) there is #reitit. Both have ~same features, including the same spec coercion.