Hi. I want to use this namespace from a yada project. But somehow there is a reference to a library we don’t need/use: https://github.com/metosin/ring-swagger/blob/master/src/ring/swagger/upload.clj#L8
Why is it imported there? Is that needed?
ring-middleware? Yes, it is required for multipart request handling
Or hmh, ring.middleware is part of ring-core
but why is it in the ring-swagger lib, is that the right place?
For easy use
When I remove the potemkin import-vars it works fine in yada. So I thought, maybe it should be moved elsewhere to not impose that dependency on yada users?
I don't see why that would break Yada
Import-vars doesn't really do anything but copy the var definition to the namespace
I know, but we don’t already have the ring.middleware.multipart-params
dependency and now I have to add it to my build?
But that namespace is from ring-core
https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/middleware/multipart_params.clj
I'm quite sure you already have ring-core
oh heh, I’ll check
It uses apache-commons so maybe there is a dependency conflict which prevents the ring namespace being loaded?
The multipart may require the servlet-api (due to ring legacy reasons)?
oh yeah, now I get:
java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
clojure.lang.ExceptionInfo: javax/servlet/http/HttpServletRequest
file: “ring/middleware/multipart_params.clj”
But I agree that ring-swagger is swollen. There is an issue to split all the functionality into smaller parts: https://github.com/metosin/schema-tools/issues/38
It is not even ring namespace which depends on servlet-api, but the commons-fileupload, and the servlet-api isn't dependency because Java reasons
spec-tools has nice little transformer utility for swagger, same should be copied to schema-tools and the whole thing would be pluggable.
(In Java environment the servelet-api would be provided by application server usually, I think)
I’ll probably just borrow this bit of code and not load the namespace as a workaround… 🙂
oh, it’s mine too 😮
But if you are going to support file uploads, you are going to need parse multipart requests, so will need the ring mutlipart middleware?
yada parses the request
but it uses ring-swagger for swagger
Yada doesn't parse multipart requests by itself
Or does Yada require the upload namespace always? And you don't even need the file uploads?
I could be mistaking, but I think it does: https://github.com/juxt/yada/blob/master/ext/multipart/src/yada/multipart.clj
I think the definitions should be separate.
Aha, true
No, I need file uploads in yada, and then I ran into this issue
The yada implementation looks good, someone should maybe port that to ring 😄
Oh well, except the manifold stuff, that wouldn't be okay for ring
I think the imports could be removed?
that seems reasonable. I’m not sure why they are there in the first place
For as simple multipart support from compojure-api, with least amount of requires: https://github.com/metosin/compojure-api/blob/e1d7eadbc7ecd56385191801e8572f9f9142fb8a/examples/thingie/src/examples/thingie.clj#L199-L203
me neither. as said, it’s swollen. Someone should have time to move the swagger2-generation to schema-tools (and by so, to ClojureScript). Anyone?
But the this part should be moved from ring-swagger to compojure-api
The namespace was probably copied from c-api originally
is there a way in compojure-api to add a specific request destructuring to all routes in a context
well i guess that isn’t actually my problem
it was a bit false alarm, since I can’t use the TempFileUpload
in yada anyway. It doesn’t support Schema coercion for multipart requests.
but at least I now know how to create a file upload in the swagger API
i can destructure at the context level, but that happens before context middleware is applied
so i guess is there a better solution than a context within a context? the first one for applying middleware and the second for destructuring
the context within a context isn’t too bad i suppose