ring-swagger

ring-swagger & compojure-api
borkdude 2018-02-15T19:14:55.000693Z

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

borkdude 2018-02-15T19:15:10.000590Z

Why is it imported there? Is that needed?

juhoteperi 2018-02-15T19:15:41.000167Z

ring-middleware? Yes, it is required for multipart request handling

juhoteperi 2018-02-15T19:16:31.000026Z

Or hmh, ring.middleware is part of ring-core

borkdude 2018-02-15T19:16:32.000568Z

but why is it in the ring-swagger lib, is that the right place?

juhoteperi 2018-02-15T19:16:40.000564Z

For easy use

borkdude 2018-02-15T19:17:29.000569Z

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?

juhoteperi 2018-02-15T19:17:43.000071Z

I don't see why that would break Yada

juhoteperi 2018-02-15T19:18:06.000402Z

Import-vars doesn't really do anything but copy the var definition to the namespace

borkdude 2018-02-15T19:18:37.000173Z

I know, but we don’t already have the ring.middleware.multipart-params dependency and now I have to add it to my build?

juhoteperi 2018-02-15T19:18:51.000485Z

But that namespace is from ring-core

juhoteperi 2018-02-15T19:19:16.000451Z

I'm quite sure you already have ring-core

borkdude 2018-02-15T19:19:26.000080Z

oh heh, I’ll check

juhoteperi 2018-02-15T19:20:05.000511Z

It uses apache-commons so maybe there is a dependency conflict which prevents the ring namespace being loaded?

ikitommi 2018-02-15T19:20:08.000017Z

The multipart may require the servlet-api (due to ring legacy reasons)?

borkdude 2018-02-15T19:21:26.000441Z

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”

ikitommi 2018-02-15T19:22:00.000277Z

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

juhoteperi 2018-02-15T19:23:11.000600Z

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

ikitommi 2018-02-15T19:23:12.000721Z

spec-tools has nice little transformer utility for swagger, same should be copied to schema-tools and the whole thing would be pluggable.

juhoteperi 2018-02-15T19:23:32.000476Z

(In Java environment the servelet-api would be provided by application server usually, I think)

borkdude 2018-02-15T19:23:44.000571Z

I’ll probably just borrow this bit of code and not load the namespace as a workaround… 🙂

ikitommi 2018-02-15T19:24:02.000725Z

https://github.com/ring-clojure/ring/issues/251

ikitommi 2018-02-15T19:24:07.000561Z

oh, it’s mine too 😮

juhoteperi 2018-02-15T19:24:36.000670Z

But if you are going to support file uploads, you are going to need parse multipart requests, so will need the ring mutlipart middleware?

borkdude 2018-02-15T19:24:51.000281Z

yada parses the request

borkdude 2018-02-15T19:25:00.000112Z

but it uses ring-swagger for swagger

juhoteperi 2018-02-15T19:25:13.000079Z

Yada doesn't parse multipart requests by itself

juhoteperi 2018-02-15T19:25:27.000191Z

Or does Yada require the upload namespace always? And you don't even need the file uploads?

borkdude 2018-02-15T19:26:02.000441Z

I could be mistaking, but I think it does: https://github.com/juxt/yada/blob/master/ext/multipart/src/yada/multipart.clj

ikitommi 2018-02-15T19:26:07.000098Z

I think the definitions should be separate.

juhoteperi 2018-02-15T19:26:13.000491Z

Aha, true

borkdude 2018-02-15T19:26:38.000198Z

No, I need file uploads in yada, and then I ran into this issue

juhoteperi 2018-02-15T19:27:10.000676Z

The yada implementation looks good, someone should maybe port that to ring 😄

juhoteperi 2018-02-15T19:27:41.000073Z

Oh well, except the manifold stuff, that wouldn't be okay for ring

ikitommi 2018-02-15T19:27:43.000338Z

I think the imports could be removed?

borkdude 2018-02-15T19:28:24.000080Z

that seems reasonable. I’m not sure why they are there in the first place

juhoteperi 2018-02-15T19:29:30.000353Z

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

ikitommi 2018-02-15T19:29:43.000761Z

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?

juhoteperi 2018-02-15T19:30:02.000270Z

But the this part should be moved from ring-swagger to compojure-api

juhoteperi 2018-02-15T19:30:30.000381Z

The namespace was probably copied from c-api originally

borkdude 2018-02-15T19:35:01.000605Z

https://github.com/metosin/ring-swagger/issues/132

2018-02-15T20:42:19.000182Z

is there a way in compojure-api to add a specific request destructuring to all routes in a context

2018-02-15T20:44:27.000485Z

well i guess that isn’t actually my problem

borkdude 2018-02-15T20:44:52.000433Z

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.

borkdude 2018-02-15T20:45:15.000424Z

but at least I now know how to create a file upload in the swagger API

2018-02-15T20:46:05.000250Z

i can destructure at the context level, but that happens before context middleware is applied

2018-02-15T20:46:38.000039Z

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

2018-02-15T20:56:57.000485Z

the context within a context isn’t too bad i suppose