ring-swagger

ring-swagger & compojure-api
lumpy 2019-03-25T17:17:53.064600Z

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))

lumpy 2019-03-25T17:18:39.065500Z

is there anyway to generate the specs from existing specs, or do they need to be manually copied?

pawel.kapala 2019-03-25T19:07:21.068700Z

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!

pawel.kapala 2019-03-25T20:11:04.069100Z

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

2019-03-25T20:11:40.070100Z

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.

ikitommi 2019-03-25T20:38:31.078Z

@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.

ikitommi 2019-03-25T20:41:34.082500Z

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).

ikitommi 2019-03-25T20:43:52.086300Z

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)))

ikitommi 2019-03-25T20:44:36.087500Z

also, just evaluating the GET form on the repl shows the internal Route definition.

ikitommi 2019-03-25T20:48:32.091800Z

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.