Fork me on GitHub
#reitit
<
2021-02-18
>
Jen W12:02:25

hiya, is there a way to overwrite the index.html that reitit-swagger-ui uses, or do I need to use ring-swagger-ui to do that? I’ve added an index.html to a swagger-ui dir in resources but it’s not picked up automatically so wondering what I’ve missed hooking up. (I’m new to reitit and pretty new to clojure too). I want to have more control over the styling and header/footer of the docs site for a reitit API Thanks!

juhoteperi12:02:55

swagger-ui/index.html in the local project SHOULD precede one from the library. Did you have the resources folder before or did you create it for this case? JVM might not pick up the folder before restarting lein (or whatever tool you are using) if you created the folder only now. Reitit swagger-ui doesn't anyway do anything special to serve the file, so you could also create our own handler to serve the index file. create-swagger-ui-handler is usually used as default handler, so if you handle the swagger-ui index on your routes, it wouldn't even see the request.

Jen W13:02:17

hmmm interesting. I did already have a /resources dir and I’m usings deps and integrant. I’ve restarted the whole project just in case but it doesn’t seem to be picking the index file. Do you have an example of what to pass to create-swagger-ui-handler to serve the index file from resources? Currently my project is wired up via integrant ig/refs passing opts of

{:path "/my-api"
                                             :url "/my-api/swagger.json"}
though to (swagger-ui/create-swagger-ui-handler opts) Reading through the docs of create-swagger-ui-handler and the linked config explanation I just don’t quite understand it well enough to know how to adjust it to have control of the index template

Jen W13:02:55

I’ve changed the dirname in my resources folder, and included that in my opts map as root and that seems to have done it. I’ve grabbed the whole dist directory from https://github.com/swagger-api/swagger-ui/tree/master/dist for the time being

juhoteperi12:02:55

swagger-ui/index.html in the local project SHOULD precede one from the library. Did you have the resources folder before or did you create it for this case? JVM might not pick up the folder before restarting lein (or whatever tool you are using) if you created the folder only now. Reitit swagger-ui doesn't anyway do anything special to serve the file, so you could also create our own handler to serve the index file. create-swagger-ui-handler is usually used as default handler, so if you handle the swagger-ui index on your routes, it wouldn't even see the request.