This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-10
Channels
- # aleph (4)
- # aws (2)
- # bangalore-clj (2)
- # beginners (84)
- # boot (25)
- # cider (3)
- # cljsrn (3)
- # clojure (57)
- # clojure-italy (5)
- # clojure-losangeles (3)
- # clojure-russia (7)
- # clojure-spec (18)
- # clojure-uk (29)
- # clojurescript (90)
- # cursive (11)
- # data-science (68)
- # datascript (2)
- # datomic (25)
- # duct (3)
- # fulcro (13)
- # graphql (7)
- # immutant (1)
- # jobs (1)
- # leiningen (12)
- # lumo (1)
- # off-topic (51)
- # om (43)
- # onyx (15)
- # parinfer (10)
- # pedestal (4)
- # re-frame (7)
- # reagent (42)
- # ring-swagger (42)
- # rum (1)
- # shadow-cljs (172)
- # spacemacs (10)
- # specter (4)
- # sql (4)
- # test-check (19)
- # unrepl (54)
- # yada (3)
Ok, I've realized that ring.middleware.format
is not a way since Compojure-api 2.0. is usig Muutanja for content negotiation. So I've ended up the code above without middleware section but it breaks Swagged docs generation
@petr.mensik does this help? https://github.com/metosin/compojure-api/wiki/2.0.0-Content-Negotiation-(with-Muuntaja)#using-muuntaja-outside-of-the-api
omg, I've read all the documentation except this part 😄
I'll try right now, thanks
(the docs are a mess as there are both pre- and post- 2.0.0 stuff. need to fix before release)
I didn't actually help, I can access the static content under "/" and api under "/api" however /docs returns 404
(defapi app
api-config
(context "/api" []
api-routes-calendar ; all of them normal (defroutes (context "/calendar" [] (GET ..etc)))
api-routes-tasks
api-routes-users)
(undocumented app-routes ; static content
not-found-routes))
api-config goes like this
(def api-config
{:swagger
{:ui "/docs"
:spec "/swagger.json"
:data {:info {:title "Bizziapp REST API documentation"
:description "Documentation which describes all REST endpoints provided by Bizziapp"}
:tags [{:name "Authentication" :description "API for auth operations"}
{:name "Users" :description "API for users operations"}]}}
:exceptions {:handlers {::ex/default bizzi-exception-handler
::custom-error bizzi-error-handler}}})
java.lang.IllegalArgumentException: don't know how to convert class java.io.InputStream into a Swagger Schema. Check out ring-swagger docs for details.
That's what I see in the log
So I guess thats the Muutanja wrap-format missing?
nope, :middleware [muuntaja.middleware/wrap-format]
makes the errors go away however then /swagger.json returns 404
(ns tst.handler
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]
[schema.core :as s]))
(s/defschema Pizza
{:name s/Str
(s/optional-key :description) s/Str
:size (s/enum :L :M :S)
:origin {:country (s/enum :FI :PO)
:city s/Str}})
(def app
(api
{:swagger
{:ui "/docs"
:spec "/swagger.json"
:data {:info {:title "Bizziapp REST API documentation"
:description "Documentation which describes all REST endpoints provided by Bizziapp"}
:tags [{:name "Authentication" :description "API for auth operations"}
{:name "Users" :description "API for users operations"}]}}}
(context "/api" []
:tags ["api"]
(GET "/plus" []
:return {:result Long}
:query-params [x :- Long, y :- Long]
:summary "adds two numbers together"
(ok {:result (+ x y)}))
(POST "/echo" []
:return Pizza
:body [pizza Pizza]
:summary "echoes a Pizza"
(ok pizza)))
(undocumented
(constantly {:status 200, :body "not found"}))))
And is there any difference between (defapi app
and (def app (api
?
I think the defapi
and defroutes
could be removed, as they just save few marks, no special handling in them.
but, the don't know how to convert class java.io.InputStream
seems to be the problem, some of your routes is marked to return InputStream
.
yes, I have a file upload there
There is no mapping for it by default, you can add one with the ring-swagger multimethods.
Routes with
:multipart-params [file :- upload/TempFileUpload]
:middleware [upload/wrap-multipart-params]
reffered from [ring.swagger.upload :as upload]
Yes, file download
(GET ":/id/download" []
:return java.io.InputStream
:summary "Returns files content for download"
:path-params [id :- Long]
:query-params [{preview :- Boolean false}]
(controller/download-file id preview))
So that's the problem?
yes. there is no code to map InputStream into a swagger definition, so the swagger-doc generation fails
(ring.swagger.json-schema/defmethod convert-class java.io.InputStream [_ _] {:type "file"})
Ok, thanks a lot, I guess I would spent a whole day digging in the code 🙂
np. I think the original error java.lang.IllegalArgumentException: don't know how to convert class java.io.InputStream into a Swagger Schema. Check out ring-swagger docs for details.
said a lot, but could have said more - like how to fix that.
Exception could also say which key caused this, and maybe which route
I'll take a look at it