Fork me on GitHub
#reitit
<
2020-04-16
>
Michaël Salihi08:04:32

Do I must use the wrap-keyword-param Ring middleware ? Or maybe Reitit Ring Coercion ? I can see this information on this issue https://github.com/metosin/reitit/issues/85: > wrap-keyword-params (reitit coercion does this, so not needed?)

Michaël Salihi13:04:10

@U055NJ5CC I found one of your answers who seems confirm that wrap-keyword-params is not mandatory to keywordize. Can you confirm please ? Any clue ? 🙂 https://clojurians-log.clojureverse.org/reitit/2018-07-30/1532938985.000098

ikitommi13:04:15

@UFBL6R4P3 the coercion middleware does the key transformations for all defined :parameters. So, if you use coercion, it’s not needed

Michaël Salihi13:04:47

Well, thank for your guidance! I will read the coercion documentation further!

markbastian18:04:07

How do I make a field a password field with swagger? I'm trying to translate https://swagger.io/docs/specification/data-models/data-types/ to edn and have tried:

["/auth" {:post       auth-handler
          :swagger    {:parameters {:password {:type   :string
                                               :format :password}}}
          :parameters {:form {:username string?
                              :password string?}}}]
That adds an unlabelled extra field. I also tried changing the :password entry in the form block to {:type :string :format :password} but no dice. Does anyone here know the right way to do it? Thanks!

ikitommi19:04:20

the swagger parameter syntax doesn"t look right. I believe it accepts a vector of maps. But I think wrapping the actual spec predicate might be easier here: {:parameters {:form {:password (spec-tools.core/spec {:spec string? :swagger {:type "string", :format "password"}}) ...}}} might work.

markbastian19:04:49

Thanks for the tip. I tried this based on what you suggested:

["/auth" {:post       auth-handler
               :swagger    {:security {}}
               :parameters {:form {:username string?
                                   :password (spec-tools.core/spec {:spec    string?
                                                                    :swagger {:type   "string"
                                                                              :format "password"}})}}}]
It still is showing the password field in plaintext. Any ideas?

bartuka19:04:56

hello, @U0JUR9FPH could you try the following:

(st/spec {:spec    string?
           :description {:swagger {:type   "string"
 :format "password"}}})
sorry bad formatting, im not enjoying this new ui 😕

markbastian20:04:54

If I understand you right, you are suggesting this:

["/auth" {:post       auth-handler
               :swagger    {:security {}}
               :parameters {:form {:username string?
                                   :password (spec-tools.core/spec {:spec        string?
                                                                    :description {:swagger {:type   "string"
                                                                                            :format "password"}}})}}}]
Still show the password.

markbastian20:04:14

The description is now [object Object].

markbastian20:04:30

Is there a "passthrough" coercion or something in which you can just use edn which is translated to swagger json? If it matter, I am using the

reitit.coercion.spec/coercion
coercion.

bartuka20:04:53

if I got this right, the transformation is handled by spec-tools.swagger.core/transform and the extra arg format is not interpreted correctly there, because it shares some code with json-schema transformation which expects this extra :description therefore: 1. We currenttly have:

(spec-tools.swagger.core/transform
 (st/spec {:spec    string?
           :swagger {:type   "string"
                     :format "password"}}))
;; => {:type "string"}
We expect
{:type "string"
 :format "password"}
EDIT: missed the point here.. there is already a dispatch specifically for swagger.

bartuka20:04:36

@U0JUR9FPH sorry for the trial and error.. seems like spec-tools.swagger is expecting namespaced keys

bartuka20:04:44

(st/spec {:spec string? :swagger/type "string" :swagger/format "password"})

bartuka20:04:50

should work.

markbastian21:04:31

Awesome! It worked. For completeness should anyone be looking, here is the complete route:

["/auth" {:post       auth-handler
               :swagger    {:security {}}
               :parameters {:form {:username string?
                                   :password (st/spec {:spec           string?
                                                       :swagger/type   "string"
                                                       :swagger/format "password"})}}}]
Thanks again for all the help!

👍 4
ikitommi04:04:50

awesome! #malli supports the plain :swagger too, it seems it's not backported to spec-tools.

bartuka20:04:38

@U055NJ5CC the backport is very simple, I made the change at https://github.com/metosin/spec-tools/pull/229 .. you can use

(st/spec {:spec string?
          :swagger {:type "string"}
          :swagger/format "password"})
;;=> {:type "string" :format "password"}
if you desired too.. my ocd does not allow me but.. people. rsrs