Fork me on GitHub
#reitit
<
2022-10-05
>
practicalli-johnny12:10:19

Is there something in reitit / swagger-ui that will write the swagger.json to disk? I have a requirement to generate a static web page of the API I’ve built with Reitit, ideally using the Redoc tool that takes in a swagger.json file and creates a static web page (there are GitHub actions that can do this if there is a swagger file) I guess I could add something that writes the generated swagger.json to disk when I start the service, or just manually download the swagger.json and save as a file (I guess it wont change that often) (background: test instances are not always available in the environment, so the live swagger-ui is not always available to other teams and production apis are not public - or in production yet)

juhoteperi13:10:33

Unfortunately the code that builds the Swagger JSON response is implemented directly in the handler function, so it is not easy call it from REPL/script: https://github.com/metosin/reitit/blob/master/modules/reitit-swagger/src/reitit/swagger.cljc#L69

juhoteperi13:10:09

It would make sense to expose create-swagger-json [router] fn.

juhoteperi13:10:41

But you could just mock the request and then call that from a script

juhoteperi13:10:40

(:body ((create-swagger-handler) {:reitit.core/router your-router})) should give you the Swagger JSON data as Clojure data structures, you can then encode as JSON yourself and write to a file.

👍 1
practicalli-johnny13:10:33

A mock request works fine for my immediate needs, thank you