Fork me on GitHub
#reitit
<
2018-06-24
>
valerauko07:06:23

I just wrote a bigger bunch of routes at once and now swagger.json is dying with this error:

500 : java.lang.IllegalArgumentException: No implementation of method: :into-spec of protocol: #'reitit.coercion.spec/IntoSpec found for class: nil
I figure I made a typo somewhere or something. Any suggestions where should I start looking? Misplaced/typoed keys? What can cause this?

ikitommi08:06:50

@vale one thing that could help is turn on the route data validation. It should catch these kind of errors: https://metosin.github.io/reitit/ring/route_data_validation.html

ikitommi08:06:52

e.g. the middleware have their own specs attached. All routes are validated againt the merged specs of all middleware (and router-level specs)

ikitommi08:06:42

not sure if the specs have a guard against nil now.

ikitommi08:06:39

for example, the request-coercion muddleware have a spec requirement of reitit.spec/parameters:

(def coerce-request-middleware
  "Middleware for pluggable request coercion.
  Expects a :coercion of type `reitit.coercion/Coercion`
  and :parameters from route data, otherwise does not mount."
  {:name ::coerce-request
   :spec ::rs/parameters
   :compile (fn [{:keys [coercion parameters]} opts]
              (if (and coercion parameters)
                (let [coercers (coercion/request-coercers coercion parameters opts)]
                  (fn [handler]
                    (fn
                      ([request]
                       (let [coerced (coercion/coerce-request coercers request)]
                         (handler (impl/fast-assoc request :parameters coerced))))
                      ([request respond raise]
                       (let [coerced (coercion/coerce-request coercers request)]
                         (handler (impl/fast-assoc request :parameters coerced) respond raise))))))))})

valerauko08:06:35

Thanks! Using validation solved it.

valerauko08:06:47

Apparently I typod a spec name somewhere else

ikitommi08:06:42

willmerge that today/tomorriw

valerauko08:06:17

i had an endpoint like this:

valerauko08:06:47

["/authorize"
    {:summary "OAuth authorization form"
     :get {:swagger {:produces #{"text/html"}}
           :handler auth-form}
     :post {:swagger {:produces #{"text/html"}}
            :responses
              {200 {:description "When no redirect URI is specified for the app
                                  in question, a HTML page is rendered with the
                                  token."}
               302 {:description "If there was a redirect URI, the user is
                                  redirected."}}
            :handler authorize}}]

valerauko08:06:05

it has a problem with the :descriptions apparently

valerauko08:06:32

it says the same if i do {200 {:swagger {:description ...}}}. what's the right way to describe responses then?

ikitommi08:06:29

uodate to 1.1.2-SNAPSHOT and it should work

ikitommi08:06:01

there is no :body and it tries to coerce nil into a spec.

ikitommi08:06:53

ups, I mean [metosin/reitit "0.1.3-SNAPSHOT"]

ikitommi08:06:29

bumpes into the same just last week when migrating a large app to reitit.

valerauko08:06:52

updated but same error still

ikitommi08:06:16

I'll check that when at computer, as a temp resolution, add a :body any? into the response data.

valerauko08:06:32

yeah that's what i did for now

👍 4