Fork me on GitHub
#malli
<
2021-03-09
>
genRaiy18:03:54

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

genRaiy18:03:09

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

genRaiy18:03:46

after swagger/transform I get

genRaiy18:03:50

{: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]}

genRaiy18:03:08

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

genRaiy18:03:35

looking at the example in reitit I see this

genRaiy18:03:39

["/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)}})}}]

genRaiy18:03:25

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

genRaiy18:03:28

any clues if you have done this already would be appreciated

ikitommi18:03:00

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

ikitommi18:03:15

you can add stuff with :swagger namespace or key:

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

genRaiy19:03:25

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

genRaiy19:03:11

I can report success 🙏:skin-tone-3:

🎉 6