malli

https://github.com/metosin/malli :malli:
raymcdermott 2021-03-09T18:06:54.262Z

I'm trying to take a simple map like this an make it consumable by reitit-swagger

raymcdermott 2021-03-09T18:07:09.262500Z

(def Org
  [:map
   [:id Id]
   [:ref string?]])

raymcdermott 2021-03-09T18:08:46.263Z

after swagger/transform I get

raymcdermott 2021-03-09T18:08:50.263300Z

{:type "object",
 :properties {:id {:type "string",
                   :pattern #"^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"},
              :ref {:type "string"}},
 :required [:id :ref]}

raymcdermott 2021-03-09T18:11:08.264Z

not sure how / where to plug this in to the reitit.swagger structure

raymcdermott 2021-03-09T18:12:35.264400Z

looking at the example in reitit I see this

raymcdermott 2021-03-09T18:12:39.264700Z

["/plus"
         {:get {:summary "plus with malli query parameters"
                :parameters {:query [:map [:x int?] [:y int?]]}
                :responses {200 {:body [:map [:total int?]]}}
                :handler (fn [{{{:keys [x y]} :query} :parameters}]
                           {:status 200
                            :body {:total (+ x y)}})}
          :post {:summary "plus with malli body parameters"
                 :parameters {:body [:map [:x int?] [:y int?]]}
                 :responses {200 {:body [:map [:total int?]]}}
                 :handler (fn [{{{:keys [x y]} :body} :parameters}]
                            {:status 200
                             :body {:total (+ x y)}})}}]

raymcdermott 2021-03-09T18:14:25.265700Z

I can see that I should decorate the Org with some swagger but still, I'm being dumb cos I can't see how to smash everything together

raymcdermott 2021-03-09T18:15:28.266100Z

any clues if you have done this already would be appreciated

ikitommi 2021-03-09T18:48:00.269300Z

@raymcdermott if the swgger-transform output is ok, just use it like {:parameters {:body Org}} and it works. swagger-transformation is done in the reitit.swagger/create-swagger-handler code for all parameters & response schemas automatically, it looks the effective :coercion for a route and asks it to transform the stuff.

ikitommi 2021-03-09T18:49:15.270400Z

you can add stuff with :swagger namespace or key:

(def Org
  [:map {:title "Org"}
   [:id {:swagger/description "id"} Id]
   [:ref {:swagger {:default "kikka"}} string?]])

ikitommi 2021-03-09T18:49:32.270500Z

here’s the code: https://github.com/metosin/reitit/blob/master/modules/reitit-swagger/src/reitit/swagger.cljc#L69-L109

😎 1
raymcdermott 2021-03-09T19:31:25.271300Z

ok - great, I'll give a go. Thanks @ikitommi

raymcdermott 2021-03-09T19:51:11.271700Z

I can report success πŸ™:skin-tone-3:

πŸŽ‰ 2