Fork me on GitHub
#reitit
<
2022-09-21
>
erwinrooijakkers19:09:59

How to make Swagger routes using reitit and pedestal? I have the following:

(ns service
  (:require
   [io.pedestal.http :as http]
   [reitit.swagger :as swagger]
   [reitit.swagger-ui :as swagger-ui]))

(def swagger-handler
  (swagger/create-swagger-handler))

(def swagger-ui-handler
  (swagger-ui/create-swagger-ui-handler))

(def ping-handler
  (fn [_req] {:status 200, :body "pong"}))

(def routes
  `[[["/api"
      ["/ping" {:get ping-handler}]]
     ^{:no-doc true}
     ["/"
      ["/swagger.json" {:get swagger-handler}]
      ["/api-docs/*" {:get swagger-ui-handler}]]]])

(def service
  {:env :prod
   ::http/routes routes
   ::http/allowed-origins [""]
   ::http/resource-path "/public"
   ::http/type :jetty
   ::http/port 3000
   ::http/host "0.0.0.0"
   ::http/container-options {:h2c? true
                             :h2? false
                             :ssl? false}})

(defonce runnable-service (server/create-server service))

(defn -main
  "The entry-point for 'lein run'"
  [& _args]
  (println "\nCreating your server...")
  (server/start runnable-service))
but this returns:
internal server exception .. Caused by: java.lang.IllegalArgumentException: No implementation of method: :compiled-routes of protocol: #'reitit.core/Router found for class: nil
The /ping route without the swagger routes does work.

rolt12:09:11

what's the server namespace ? the error makes me think it's a reitit namespace. If you want to use pedestal with retit routing, you're supposed to build a pedestal server with no routes, and replace the last interceptor with the reitit router