This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-05
Channels
- # announcements (14)
- # aws (7)
- # babashka (28)
- # beginners (16)
- # calva (2)
- # cider (1)
- # clj-commons (8)
- # clj-kondo (29)
- # clojure (213)
- # clojure-europe (39)
- # clojure-losangeles (2)
- # clojure-norway (9)
- # clojure-spec (2)
- # clojurescript (11)
- # community-development (1)
- # conjure (2)
- # cursive (6)
- # datalevin (2)
- # datomic (8)
- # emacs (29)
- # events (1)
- # fulcro (22)
- # graalvm (14)
- # improve-getting-started (1)
- # jobs (1)
- # lambdaisland (5)
- # leiningen (4)
- # lsp (7)
- # malli (13)
- # meander (11)
- # membrane (13)
- # off-topic (23)
- # polylith (9)
- # re-frame (4)
- # reagent (7)
- # reitit (6)
- # releases (2)
- # sql (58)
- # testing (8)
- # tools-deps (18)
- # web-security (2)
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)
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
It would make sense to expose create-swagger-json [router]
fn.
But you could just mock the request and then call that from a script
(: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.
A mock request works fine for my immediate needs, thank you