Fork me on GitHub
#reitit
<
2022-05-16
>
Roderick Mallard23:05:57

Hi there. I was wondering if anyone might have hints or pointers for understanding the interaction of reitit, malli, and custom registries? I think this might be related to what @weavejester was asking about, above. I think my question boils down to, if I build a coercer with a provided registry, like:

(def schemas
  (merge
   (m/default-schemas)
   {::id string?
    ::timestamp inst?
    ::thing
    [:map {:closed true}
     [:id ::id]
     [:other ::id]
     [:timestamp inst?]]}))

(def registry-coercion
  (reitit.coercion.malli/create
   (assoc reitit.coercion.malli/default-options
          :options {:registry (mr/registry schemas)})))
... what's the right way to provide schema information to an operation? Things like the following don't seem to work -- swagger-ui invariably reports 'Could not resolve reference.' --
(def thing
  (m/schema ::thing {:registry schemas}))

(def app
  (ring/ring-handler
   (ring/router
    [["/swagger.json"
      {:get {:no-doc true
             :swagger {:info {:title "my-api"}}
             :handler (swagger/create-swagger-handler)}}]
     ["" {:coercion registry-coercion}
      ["/echo"
       {:post {:summary "Echo a coerced complex type."
               :parameters {:body thing}
               :swagger {:responses {400 {:schema {:type "string"}}}}
               :responses {200 {:body thing}
                           500 {:description "fail"}}
               :handler (fn [{{xs :body} :parameters}]
                          {:status 200
                           :body xs})}}]]]

    {:exception pretty/exception
     :data {:coercion registry-coercion
    ... etc
Pointers into code are most welcome. Just wondering if I've already gone so far off course that my error is evident. Cheers! (oh, by the way, if I just use def'ed m/schema instances, it all works fine)