reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
2020-04-16T08:19:32.114300Z

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

2020-04-16T13:04:10.116400Z

@ikitommi 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

ikitommi 2020-04-16T13:13:15.116700Z

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

2020-04-16T13:21:47.116900Z

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

2020-04-16T18:13:07.119800Z

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!

bartuka 2020-04-17T20:22:38.123900Z

@ikitommi 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

ikitommi 2020-04-16T19:24:20.119900Z

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.

2020-04-16T19:42:49.120100Z

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?

bartuka 2020-04-16T19:57:56.120300Z

hello, @markbastian could you try the following:

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

2020-04-16T20:02:54.120900Z

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.

2020-04-16T20:04:14.121100Z

The description is now [object Object].

2020-04-16T20:08:30.121500Z

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.

bartuka 2020-04-16T20:10:53.121800Z

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.

bartuka 2020-04-16T20:26:36.122200Z

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

bartuka 2020-04-16T20:26:44.122400Z

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

bartuka 2020-04-16T20:26:50.122600Z

should work.

2020-04-16T21:19:31.123Z

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!

πŸ‘ 1