reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
eric.shao 2020-04-07T02:37:47.057700Z

Hello. How to setup retitit-swagger to group APIs under different group names? Is there a piece of code sample? THX!😊

ikitommi 2020-04-07T05:29:23.059500Z

should it be (spec-tools.core/spec …)instead?

eric.shao 2020-04-07T05:52:21.061400Z

@ikitommi 😀Thank you for your reply. I don’t describe clear, Is there a way to have a Two-level Group? A big group contains many secondary groups.

ikitommi 2020-04-07T05:59:46.063100Z

uthere is no such thing in swagger, but we have used tag names like admin, admin.users, admin.products etc. Flat, but looks nested.

ikitommi 2020-04-07T06:01:04.064100Z

You could post an issue asking this into swagger-ui repo, if there would be such a grouping available nowadays, please paste the result here too.

eric.shao 2020-04-07T06:03:48.065Z

Maybe gen many swagger spec?

eric.shao 2020-04-07T06:04:21.065600Z

😀Thank you @ikitommi for your reply.

ikitommi 2020-04-07T06:06:13.066100Z

oh, forgot, there is also https://cljdoc.org/d/metosin/reitit/0.4.2/doc/ring/swagger-support#multiple-swagger-apis

ikitommi 2020-04-07T06:06:44.066700Z

e.g. you can easily groups the apis into separate swagger specs too.

eric.shao 2020-04-07T06:07:23.067100Z

:hugging_face: Thank you!!!

Misha Bohdan 2020-04-07T08:45:04.067200Z

Sorry, I looked at my code to check `(spec-tools.core/spec …)` and found that it already used.

sudakatux 2020-04-07T12:56:05.067500Z

Hi

sudakatux 2020-04-07T12:56:17.067800Z

I cant seem to get this example to work

sudakatux 2020-04-07T12:56:21.068100Z

["/upload"
    {:post {:summary "upload a file"
            :parameters {:multipart [:map [:file reitit.ring.malli/temp-file-part]]}
            :responses {200 {:body [:map [:name string?] [:size int?]]}}
            :handler (fn [{{{:keys [file]} :multipart} :parameters}]
                       {:status 200
                        :body {:name (:filename file)
                               :size (:size file)}})}}]

sudakatux 2020-04-07T12:56:38.068400Z

im using

[metosin/reitit "0.4.2"]

ikitommi 2020-04-07T12:56:53.069Z

do you have the multipart-middleware mounted?

sudakatux 2020-04-07T12:56:55.069200Z

The middleware seems to be "the problem"

sudakatux 2020-04-07T12:57:02.069400Z

yes

sudakatux 2020-04-07T12:57:15.069900Z

{:middleware [;; query-params & form-params
                 parameters/parameters-middleware
                 ;; content-negotiation
                 muuntaja/format-negotiate-middleware
                 ;; encoding response body
                 muuntaja/format-response-middleware
                 ;; exception handling
                 exception/exception-middleware
                 ;; decoding request body
                 muuntaja/format-request-middleware
                 ;; coercing response bodys
                 coercion/coerce-response-middleware
                 ;; coercing request parameters
                 coercion/coerce-request-middleware
                 ;; multipart params
                 multipart/multipart-middleware]
    :muuntaja   formats/instance

ikitommi 2020-04-07T12:57:21.070100Z

that is directly from the example project?

sudakatux 2020-04-07T12:57:26.070400Z

["/api"
   {:middleware [;; query-params & form-params
                 parameters/parameters-middleware
                 ;; content-negotiation
                 muuntaja/format-negotiate-middleware
                 ;; encoding response body
                 muuntaja/format-response-middleware
                 ;; exception handling
                 exception/exception-middleware
                 ;; decoding request body
                 muuntaja/format-request-middleware
                 ;; coercing response bodys
                 coercion/coerce-response-middleware
                 ;; coercing request parameters
                 coercion/coerce-request-middleware
                 ;; multipart params
                 multipart/multipart-middleware]
    :muuntaja   formats/instance
    :coercion   malli-coercion/coercion

sudakatux 2020-04-07T12:57:40.070600Z

No

sudakatux 2020-04-07T12:57:45.070800Z

just copied that endpoint

ikitommi 2020-04-07T12:58:01.071Z

will test the project

sudakatux 2020-04-07T12:58:41.071600Z

it seems like the middleware is not adding the :multipart parameter

sudakatux 2020-04-07T12:59:17.072400Z

because if i ignore the middleware and i hit :multipart-param directly I do see the file

ikitommi 2020-04-07T12:59:37.072700Z

Just tested the example project and it works ok.

ikitommi 2020-04-07T13:00:50.073500Z

try adding the :reitit.middleware/transform reitit.ring.middleware.dev/print-request-diffs router option

sudakatux 2020-04-08T11:29:45.074800Z

Thanks this really helped me understand lots of things

ikitommi 2020-04-07T13:01:01.073800Z

should print what’s going on.

sudakatux 2020-04-07T13:01:10.074100Z

cool thanks will try

Misha Bohdan 2020-04-07T13:18:47.074400Z

Solution found: extending base reitit.coercion.spec/default-options with somethis like this

(def custom-transformer
   (st/type-transformer
     {:name     ::custom-transformer
      :decoders {:my-data #(str->my-data %2)}
      :encoders (:my-data #(my-data->str %2))}))