Fork me on GitHub
#reitit
<
2019-12-04
>
schmandle14:12:36

@ikitommi I posted a minimal repro above. It needs all the boilerplate since the problem does not show up when calling encode directly

markbastian15:12:53

I have a problem that I hope can be solved via a simple config change that I can't figure out. I have an api created with routes using reitit and I am also creating the swagger-ui endpoint. The app is deployed via aws api gateway. Let's say the endpoint is https://myapi.execute-api.us-east-1.amazonaws.com. The api gateway then allows you to create stages (e.g. dev) so that the base url is now (for dev) https://myapi.execute-api.us-east-1.amazonaws.com/dev. My routes all work just fine with this, but my swagger api is unaware of the dev part of the path. Is there something I can do to resolve the base url correctly? Here is my router code for reference. Adding the :url parameter allows my api-docs endpoint to correctly resolve to swagger.json file, but then all the endpoints it references don't have the dev part of the path in them.

(def router
  (ring/router
    [["/api" {:swagger {:tags    ["basic api"]
                        :summary "This is the api"}}
      ["/time" {:get (fn [_] (ok (str "The time is: " (Date.))))}]]
     ["" {:no-doc true}
      ["/swagger.json" {:get (swagger/create-swagger-handler)}]
      ["/api-docs*" {:get (swagger-ui/create-swagger-ui-handler {:url "/dev/swagger.json"})}]]]
    {:data {:coercion   reitit.coercion.spec/coercion
            :middleware [params/wrap-params
                         middleware/wrap-format]}}))

(def handler
  (ring/ring-handler
    router
    (constantly (not-found "Not found"))))

ikitommi15:12:52

@markbastian try setting :basePath under swagger, e.g. {:swagger {:basePath "/dev"}}

ikitommi15:12:14

just needed for the swagger spec endpoint, so into the properties which has the :no-doc now

markbastian15:12:28

Perfect! Thanks so much for the help (and for the awesome library). For completeness, here's the working router should anyone else run into this:

(def router
  (ring/router
    [["/api" {:swagger {:tags    ["basic api"]
                        :summary "This is the api"}}
      ["/time" {:get (fn [_] (ok (str "The time is: " (Date.))))}]]
     ["" {:no-doc true
          :swagger {:basePath "/dev"}}
      ["/swagger.json" {:get (swagger/create-swagger-handler)}]
      ["/api-docs*" {:get (swagger-ui/create-swagger-ui-handler {:url "/dev/swagger.json"})}]]]
    {:data {:coercion   reitit.coercion.spec/coercion
            :middleware [params/wrap-params
                         middleware/wrap-format]}}))