Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure Compojure api不尊重ring.mock.requests中的主体_Clojure_Ring_Compojure Api - Fatal编程技术网

Clojure Compojure api不尊重ring.mock.requests中的主体

Clojure Compojure api不尊重ring.mock.requests中的主体,clojure,ring,compojure-api,Clojure,Ring,Compojure Api,我正在尝试使用ring.mock.requests库来测试http服务。我有这段代码 (auth-routes (-> (mock/request :post "/auth/user") (mock/body {:username "user" :password "pass"}) (mock/content-type "application/json"))) thread first宏的内部部分似乎工作正常,但当我尝试

我正在尝试使用ring.mock.requests库来测试http服务。我有这段代码

   (auth-routes    
     (->
       (mock/request :post "/auth/user")
       (mock/body {:username "user" :password "pass"})
       (mock/content-type "application/json")))
thread first宏的内部部分似乎工作正常,但当我尝试发出验证路由的模拟请求时,它失败了

这是我的路线:

(def auth-routes
  (context "/auth" []
  :tags ["Authentication"]
    (POST "/user" []
      :return s/Uuid
      :body [request m/User]
      :summary "Create new user"
      (ok (auth/create-user request)))) ...)
这是我的模式:

(def User {:username s/Str
           :password s/Str})
我看到的例外是

clojure.lang.ExceptionInfo
   Request validation failed
   {:error (not (map? nil)), :type :compojure.api.exception/request-validation}
看起来我的路线是以
nil
为主体的,我希望
{:username“user”:password“pass”}
在那里


我做错了什么?如何将主体传递到此路由?

我认为您应该在测试中将数据序列化为json字符串。使用:


查看或。

您的
auth routes
定义是否正确?您的
POST”/user“[]
不应该类似于
POST”/user”请求吗?
?通过compojure api示例可以看出这是正确的,我认为您需要序列化。看一看。我还创建了一个小程序来测试它,它正在工作。你的示例对我来说很有用,但是当我删除序列化时,我会得到一个不同的错误。在您的示例中,我看到您正在使用
api
函数包装路由,我在这里没有这样做,因为我在其他地方将它们放在一起。因为我忽略了这一点,compojure api的:body参数(当然)没有得到尊重。
(cheshire.core/generate-string {:username "user" :password "pass"})