ring-swagger

ring-swagger & compojure-api
daniel.spaniel 2019-11-27T15:28:01.015200Z

Howdy, I setup ring-swagger as the docs explained ( added to deps.edn )

metosin/ring-swagger                          {:mvn/version "0.26.2"}
             metosin/ring-swagger-ui                       {:mvn/version "3.20.1"}
used the example json ( in file that is required by my middleware.clj file that requires ring-middleware and handles ring requests )
(s/defschema User {:id      s/Str,
                   :name    s/Str
                   :address {:street s/Str
                             :city   (s/enum :tre :hki)}})

(s/with-fn-validation
  (rs/swagger-json
    {:info {:version "1.0.0"
            :title "Sausages"
            :description "Sausage description"
            :termsOfService "<http://helloreverb.com/terms/>"
            :contact {:name "My API Team"
                      :email "<mailto:foo@example.com|foo@example.com>"
                      :url "<http://www.metosin.fi>"}
            :license {:name "Eclipse Public License"
                      :url "<http://www.eclipse.org/legal/epl-v10.html>"}}
     :tags [{:name "user"
             :description "User stuff"}]
     :paths {"/api/ping" {:get {}}
             "/user/:id" {:post {:summary "User Api"
                                  :description "User Api description"
                                  :tags ["user"]
                                  :parameters {:path {:id s/Str}
                                               :body User}
                                  :responses {200 {:schema User
                                                   :description "Found it!"}
                                              404 {:description "Ohnoes."}}}}}}))
restarted everything, went to localhost:300/swagger.json and did not see anything Am I missing something ?

ikitommi 2019-11-27T17:29:48.019500Z

@dansudol swagger-json is a pure function to create a swagger spec. You need to serve that yourself. See https://github.com/metosin/compojure-api how it uses ring-swagger to emit swagger docs out of compojure routes

daniel.spaniel 2019-11-27T17:50:51.021900Z

we are not using composure for routing but rather just handling routing ourselves in ring middleware , do i need to setup composure or should I return this json and let my front end framework ( fulcro ) show the json as swagger ( I am so confused )

ikitommi 2019-11-27T17:58:10.025400Z

you need to have a route that serves the generated spec as json. Swagger-ui is configured to use that path (for example "/swagger.json") to genererate the ui from. Hope this helps

daniel.spaniel 2019-11-27T18:00:12.026400Z

oh .. ok .. so i would manually set up a public route that served back my swagger json .. from a route named swagger.json

daniel.spaniel 2019-11-27T18:00:25.026800Z

sorta makes sense .. i will try that now

daniel.spaniel 2019-11-27T19:05:46.027600Z

ok .. i have the backend returning the swagger json .. now, how would i get the nice swagger UI look and feel for the front end ?

daniel.spaniel 2019-11-27T19:06:07.028200Z

is there a way to convert that json to html before i return the json ( or instead of the json ) ?