Fork me on GitHub
#ring-swagger
<
2017-05-12
>
maja12:05:50

Hi all! I am not very experienced with Clojure, but I am wondering if it is possible to use compojure-api using clojure.spec instead of Schema? To my understanding this means the swagger docs will not be generated, but is it possible to use to make an API anyway?

ikitommi13:05:23

@maja yes and no. Compojure-api builds on compojure.api.routes/Route-records. You can create a custom`Route` that validates with spec and mount it to the routing tree just like GET, resource & others.

romain13:05:01

@ikitommi any road map for upgrading to swagger 3.x?

ikitommi13:05:18

Idea is to make tje validation lib pluggable, schema, spec or any other. We try to get this right, so need some thinking before finalizing (have a almost working branch with resources). Also, plumbing might need a PR.

ikitommi13:05:13

@romain yes, as soon as have time. Contributions would be welcome.

ikitommi13:05:52

we are doing now the spec->swagger2, openapi3 would be easy after that. Merge with ring-swagger after that. My guess is that all is done before the midsummer party.

romain13:05:33

@ikitommi do you have any doc or guide to help getting in?

ikitommi13:05:36

@romain ring-swagger source :) It could have a openapi3 ns, just like there is swagger2

ikitommi13:05:08

JSON Schema support is better in 3, the version could be passed into the tranformation functions.

ikitommi13:05:34

e.g. reuse the ring.swagger.json-schema for both.

maja13:05:37

I see, thanks a lot @ikitommi and @romain 🙂

ikitommi13:05:01

the spec-swagger/openapi stuff lives in https://github.com/metosin/spec-swagger, we can develop it parallel to the schema+openapi3.

ikitommi13:05:51

np. Would be awesome if you could cook up the 3 support for Schema.

ikitommi13:05:59

Btw, new (async) ring 1.6.0 versions of all our ring libs are now out (ring-http-response, ring-swagger, muuntaja, compojure-api)

romain14:05:24

I'm still new to ring, swagger and Clojure contributions, I will try to give a look the project doesn't seem to be complicated and heavy

romain14:05:16

The specifications for 3.0 are still in draft but it should enough to start

slpssm16:05:01

Hi. I’ve updated my app to use compojure-api from 1.0.1 to 1.1.10 and the swagger UI stopped working. I’ve changed the calls to swagger-ui and swagger-docs to swagger-routes but swagger.json is empty. I saw this note in the CHANGELOG for 1.1.0 and think it is relevant but I’m not sure what I need to do.

api-level swagger-options default to {:ui nil, :spec nil}. Setting up just the spec or ui, doesn't automatically setup the other (like previously)
Any suggestions?

miikka16:05:21

Hmmh, if you're explicitly calling swagger-routes, that shouldn't matter, because that should setup both.

slpssm16:05:22

Oh, yes. Been reading code. Still not sure why swagger.json is empty even though it worked fine before the upgrade. 😞

miikka16:05:38

It could be because for some reason the ring-swagger swagger-data middleware is not included

miikka17:05:18

Do you have the ring-middleware-format middleware enabled? I.e. non-nil :format. Because that looks like that the swagger data middleware is enable only if the format middleware is enabled.

slpssm17:05:20

Let me check

slpssm17:05:18

Looks like yes. Have this: :format {:formats [:json-kw :edn :transit-json]} in the api call.

miikka17:05:56

That should work, then

miikka17:05:18

How empty is your swagger.json? Like, no-body-at-all, or 404, or like some JSON but without paths and definitions?

slpssm17:05:12

204 no content empty. I went back to the old calls to swagger-docs and swagger-routes and now I get

500 : {"error":{"type":"unknown-error","message":"Key must be integer"}}

miikka17:05:59

I'd probably call get-routes on the result of your api call to check that swagger.json is mounted where you think it should be mounted, or anywhere at all. And I assume you get a stacktrace for that error in console, or something?

slpssm17:05:23

That is another issue, my logging is gone too. I’m going to wind back a bunch of upgraded packages, then start adding them back and see where the issue reoccurs.

miikka17:05:11

Oh, okay, that's bad 😞

slpssm18:05:03

Just for information, the issue was I added a responses to a route without actually knowing how and it was bad. Removing it fixed the issue. It looked like:

:responses {400 [String]}
😞

miikka18:05:31

Ah well. There should be some kind of validation instead of things just mysteriously breaking.