Fork me on GitHub
#ring-swagger
<
2017-11-10
>
petr.mensik08:11:04

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.mensik10:11:24

omg, I've read all the documentation except this part 😄

petr.mensik10:11:33

I'll try right now, thanks

ikitommi10:11:33

(the docs are a mess as there are both pre- and post- 2.0.0 stuff. need to fix before release)

petr.mensik11:11:16

I didn't actually help, I can access the static content under "/" and api under "/api" however /docs returns 404

petr.mensik11:11:11

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

ikitommi11:11:55

how does your api-config look? (the swagger-parts)

petr.mensik11:11:58

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

ikitommi11:11:18

does the /swagger.json return the swagger json?

petr.mensik11:11:50

java.lang.IllegalArgumentException: don't know how to convert class java.io.InputStream into a Swagger Schema. Check out ring-swagger docs for details.

petr.mensik11:11:56

That's what I see in the log

petr.mensik11:11:29

So I guess thats the Muutanja wrap-format missing?

petr.mensik11:11:39

nope, :middleware [muuntaja.middleware/wrap-format] makes the errors go away however then /swagger.json returns 404

ikitommi11:11:44

I did a sample from compojure-api template, with latest alpha and this handler:

ikitommi11:11:47

(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"}))))

ikitommi11:11:28

it works ok. api binds the muuntaja-stuff with defaults.

petr.mensik11:11:53

And is there any difference between (defapi app and (def app (api?

ikitommi11:11:48

no. same with (def r (routes ...)) and (defroutes r ...)

ikitommi11:11:22

I think the defapi and defroutes could be removed, as they just save few marks, no special handling in them.

ikitommi11:11:34

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 .

petr.mensik11:11:54

yes, I have a file upload there

ikitommi11:11:02

There is no mapping for it by default, you can add one with the ring-swagger multimethods.

petr.mensik11:11:18

Routes with

:multipart-params [file :- upload/TempFileUpload]
      :middleware [upload/wrap-multipart-params]

petr.mensik11:11:44

reffered from [ring.swagger.upload :as upload]

ikitommi11:11:56

but do you have somewhere :return InputStream?

petr.mensik11:11:17

Yes, file download

petr.mensik11:11:26

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

petr.mensik11:11:31

So that's the problem?

ikitommi11:11:07

yes. there is no code to map InputStream into a swagger definition, so the swagger-doc generation fails

ikitommi11:11:55

(ring.swagger.json-schema/defmethod convert-class java.io.InputStream            [_ _] {:type "file"})

ikitommi11:11:58

should fix that.

ikitommi11:11:07

or just remove the :return

petr.mensik11:11:31

Ok, thanks a lot, I guess I would spent a whole day digging in the code 🙂

ikitommi11:11:18

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.

juhoteperi11:11:10

Exception could also say which key caused this, and maybe which route

petr.mensik12:11:56

I'll take a look at it

oahner21:11:13

I have a strange issue with compojure-api; my :body-params is sometimes nil even tho :body does contain a valid payload

oahner21:11:06

Even stranger, it only happens with Undertow; with http-kit it works fine