Fork me on GitHub
#reitit
<
2023-05-03
>
opqdonut14:05:55

🎉 21
p-himik22:05:00

Trying to use it but get an error in Swagger UI:

Unable to render this definition
The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).
Seems like the UI wasn't updated to be compatible with OpenAPI 3.1. But maybe I'm doing something wrong - any clues?

p-himik22:05:17

The /openapi.json endpoint has "openapi": "3.1.0",.

p-himik22:05:46

Ah, I had to manually specify the latest metosin/ring-swagger-ui in my deps. Otherwise, the latest alpha of metosin/reitit-swagger-ui is pulling an older version.

p-himik01:05:51

Some other feedback: :example is ignored in parameters (documented here: https://swagger.io/docs/specification/adding-examples/). But at least I can provide :json-schema/example.

p-himik02:05:50

Also, query parameter description doesn't show up. However, the whole map schema description does show up for every parameter. So if I use :query [:map [:x {:description "hi"} :string]], that "hi" will not be shown. But if I use :query [:map {:description "hi"} [:x :string] [:y :int]], that "hi" will show up for both x and y.

opqdonut06:05:09

thanks, sorry about the ring-swagger-ui version mixup. need to sort that up before release

opqdonut06:05:11

and yeah :json-schema/example probably needs more docs

Felipe19:05:02

if I want to clean up (e.g. trim + lower-case a field) some wire input that's spec'd with malli before it reaches the handler, where should that go? custom interceptor? decode/string?

ikitommi19:05:52

• :decode/string for query, path, header and form params • :decode/json form JSON

gratitude-thank-you 2
ikitommi19:05:18

there was just discussion few days back about “for all formats” transformer

Felipe19:05:17

yeah, I went through that thread three times but couldn't make it work for application/transit+json and have no idea how to debug it

ikitommi19:05:41

sadly, it has no default transformers set with malli.

ikitommi19:05:53

please write an issue of this? would be easy to add such a thing.

ikitommi19:05:56

now, one can set extra transformers via custom config, but that’s a lot of boilerplate and there is no proper guide how to do that.

ikitommi19:05:36

if you are in a hurry, add a custom interceptor (before request-coercion-interceptor) for this.

đź‘Ť 2
Felipe19:05:21

what I tried was

(def coercion
  (rcm/create (update-in rcm/default-options
                         [:transformers :body :formats]
                         assoc
                         "application/edn" rcm/string-transformer-provider
                         "application/transit+json" rcm/string-transformer-provider)))
should that + decode/string be enough?

ikitommi06:05:22

yes, that should be.

ikitommi06:05:19

would you time to add this to documentation?

ikitommi06:05:09

“how to enable string-coercion with edn & transit” kinda tip.

Felipe09:05:29

it didn’t work though. I’ll have time today to both try it again, write some docs and create a gh issue

Felipe13:05:29

ok, got it to work in ring_coercion_test:

["/body" {:summary "decoding for non-json"
                                                        :coercion (reitit.coercion.malli/create {:transformers
                                                                                                 {:body
                                                                                                  {:formats
                                                                                                   {"application/edn"
                                                                                                    reitit.coercion.malli/string-transformer-provider}}}})
                                                        :post {:parameters {:body [:map
                                                                                   [:x
                                                                                    {:decode/string clojure.string/lower-case}
                                                                                    string?]]}
                                                               :responses {200 {:body [:map [:x string?]]}}
                                                               :handler (fn [req]
                                                                          {:status 200
                                                                           :body (-> req :parameters :body)})}}]
must be doing something else wrong in the main project repo. thanks for the help! later today will have a PR with the tip

Felipe15:05:42

found out that no transformers get applied ever for the body, even if I try a JSON decoder / payload / content-type. maybe because we're not using muuntaja for content negotiation? any tips for debugging what might be happening?