看不到Swagger服务端点

问题描述 投票:1回答:2

我正在尝试访问Swagger服务端点。这是代码:

(defn service-routes []
  ["/api"
   {:middleware [middleware/wrap-formats]
    :swagger {:id ::api}}
   ["" {:no-doc true}
    ["/swagger.json"
     {:get (swagger/create-swagger-handler)}]
    ["/swagger-ui*"
     {:get (swagger-ui/create-swagger-ui-handler
             {:url "api/swagger.json"})}]]
   ["/business-partners"
    {:get
     (fn [_]
       (response/ok (bp/business-partners-list)))}]
   ["/business-partner"
    {:post
     (fn [{:keys [params]}]
       (try
         (bp/save-business-partner params)
         (response/ok {:status :ok})
         (catch Exception e
           (let [{id :business-partners/error-id
                  errors :errors} (ex-data e)]
             (case id
               :validation
               (response/bad-request {:errors errors})
               (response/internal-server-error
                 {:errors {:server-error ["Failed to save message!"]}}))))))}]])

但是当我尝试在浏览器中访问http://localhost:3000/api/swagger.json时,得到了以下响应:

{"swagger":"2.0",
 "x-id":["businesspartners.routes.services/api"],
 "paths":{
   "/api/business-partners": {"get":  {}},
   "/api/business-partner":  {"post": {}}}}

我不知道为什么我会以json格式获取它,为什么不看到Swagger UI使服务变成虚假的并与我的服务进行交互?我应该得到这样的东西:

enter image description here

clojure swagger swagger-ui
2个回答
0
投票

我想您会在/ api下找到招摇的ui


0
投票

我也面临着同样的问题,并且在Java和语言jaxrs中使用代码生成生成代码后,将在target / generate-sources / swagger /文件夹下看到带有端点生成的index.html页面。确保在构建中包括它并将api路径指向此页面,以便可以将端点查看为html。

© www.soinside.com 2019 - 2024. All rights reserved.