2024 年 Clojure 状况调查!中分享您的想法。

欢迎!请查看关于页面以了解更多有关此网站如何运作的信息。

0 投票

嘿!我在reitit的例子http-swagger项目中得到了这个函数,遇到了不匹配括号错误。

(def app
  (http/ring-handler
   (http/router
     [["/swagger.json"
        {:get {:no-doc true
         :swagger {:info {:title "my-api"
                          :description "with reitit-http"}}
         :handler (swagger/create-swagger-handler)}}]

 ["/files"
  {:swagger {:tags ["files"]}}

  ["/upload"
   {:post {:summary "upload a file"
           :parameters {:multipart {:file multipart/temp-file-part}}
           :responses {200 {:body {:name string?, :size int?}}}
           :handler (fn [{{{:keys [file]} :multipart} :parameters}]
                      {:status 200
                       :body {:name (:filename file)
                              :size (:size file)}})}}]

 ["/async"
  {:get {:swagger {:tags ["async"]}
         :summary "fetches random users asynchronously over the internet"
         :parameters {:query (s/keys :req-un [::results] :opt-un [::seed])}
         :responses {200 {:body any?}}
         :handler (fn [{{{:keys [seed results]} :query} :parameters}]
                    (d/chain
                     (aleph/get
                      "https://randomuser.me/api/"
                      {:query-params {:seed seed, :results results}})
                     :body
                     (partial m/decode "application/json")
                     :results
                     (fn [results]
                       {:status 200
                        :body results})))}}]

 ["/math"
  {:swagger {:tags ["math"]}}

  ["/plus"
   {:get {:summary "plus with data-spec query parameters"
          :parameters {:query {:x int?, :y int?}}
          :responses {200 {:body {:total pos-int?}}}
          :handler (fn [{{{:keys [x y]} :query} :parameters}]
                     {:status 200
                      :body {:total (+ x y)}})}
    :post {:summary "plus with data-spec body parameters"
           :parameters {:body {:x int?, :y int?}}
           :responses {200 {:body {:total int?}}}
           :handler (fn [{{{:keys [x y]} :body} :parameters}]
                      {:status 200
                       :body {:total (+ x y)}})}}]

  ["/minus"
   {:get {:summary "minus with clojure.spec query parameters"
          :parameters {:query (s/keys :req-un [::x ::y])}
          :responses {200 {:body (s/keys :req-un [::total])}}
          :handler (fn [{{{:keys [x y]} :query} :parameters}]
                     {:status 200
                      :body {:total (- x y)}})}
    :post {:summary "minus with clojure.spec body parameters"
           :parameters {:body (s/keys :req-un [::x ::y])}
           :responses {200 {:body (s/keys :req-un [::total])}}
           :handler (fn [{{{:keys [x y]} :body} :parameters}]
                      {:status 200
                       :body {:total (- x y)}})}}]]]

{:reitit.interceptor/transform dev/print-context-diffs ;; pretty context diffs
 :validate spec/validate ;; enable spec validation for route data
 :reitit.spec/wrap spell/closed ;; strict top-level validation
 :exception pretty/exception
 :data {:coercion reitit.coercion.spec/coercion
        :muuntaja m/instance
        :interceptors [;; swagger feature
                       swagger/swagger-feature
                       ;; query-params & form-params
                       (parameters/parameters-interceptor)
                       ;; content-negotiation
                       (muuntaja/format-negotiate-interceptor)
                       ;; encoding response body
                       (muuntaja/format-response-interceptor)
                       ;; exception handling
                       (exception/exception-interceptor)
                       ;; decoding request body
                       (muuntaja/format-request-interceptor)
                       ;; coercing response bodys
                       (coercion/coerce-response-interceptor)
                       ;; coercing request parameters
                       (coercion/coerce-request-interceptor)
                       ;; multipart
                       (multipart/multipart-interceptor)]}})
 (ring/routes
(swagger-ui/create-swagger-ui-handler
 {:path "/"
  :config {:validatorUrl nil
           :operationsSorter "alpha"}})
(ring/create-default-handler))
 {:executor sieppari/executor}))

2 个回答

0 投票

最好是去https://github.com/metosin/reitit/issues提交一个问题。

0 投票

尝试在70行(:body {:total (- x y)}}VALUES)()])的行尾添加一个额外的]以关闭向量。是的,正如@alexmiller所说,最好是向reitit提交一个问题。

欢迎来到Clojure问答,在这里您可以提出问题并从Clojure社区的成员那里获得答案。
...