Fork me on GitHub
#ring-swagger
<
2019-11-27
>
daniel.spaniel15:11:01

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 ""
            :contact {:name "My API Team"
                      :email ""
                      :url ""}
            :license {:name "Eclipse Public License"
                      :url ""}}
     :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 ?

ikitommi17:11:48

@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.spaniel17:11:51

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 )

ikitommi17:11:10

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.spaniel18:11:12

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

daniel.spaniel18:11:25

sorta makes sense .. i will try that now

daniel.spaniel19:11:46

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.spaniel19:11:07

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