[英]Compojure API running ring server raises map exception
我正在關注本教程,了解如何使用組合 api 並遇到此異常的死胡同:
lein ring server
2022-08-09 23:19:55.538:INFO::main: Logging initialized @921ms
WARN clojure.tools.logging not found on classpath, compojure.api logging to console.
Exception in thread "main" java.lang.RuntimeException: Map literal must contain an even number of forms, compiling:(ring_test/core.clj:16:16)
除了將路線更改為測試路線外,我的所有內容都與教程相同:
(ns ring-test.core
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]))
(def app
(api
{:swagger
{:ui "/"
:spec "swagger.json"
:data {:info {:tile "Test"}
:tags [{:name "api"}]}}
(context "/api" []
:tags ["api"]
(GET "/test" []
:body ["test"]
(ok)))}))
並更新了project.clj
中的一些版本:
(defproject ring-test "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]
[metosin/compojure-api "2.0.0-alpha28"]]
:ring {:handler ring-test.core/app}
:profiles {:dev
{:plugins [[lein-ring "0.12.5"]]
:dependencies [[javax.servlet/servlet-api "2.5"]]}})
如果有人可以幫助我解決這個問題,那就太棒了!
在本教程中,(上下文...)在 map 之外。
(def app
(api {:swagger
{:ui "/"
:spec "/swagger.json"
:data {:info {:title "Account Service"}
:tags [{:name "api"}]}}} ;; END-OF-MAP HERE
;; This from is _NOT_ in the map
(context "/api" []
:tags ["api"]
(POST "/account" []
:body [account (describe NewAccount "new account")]
(ok))
(POST "/transfer" []
:body [transfer (describe NewTransfer "new transfer")]
(ok)))))
問題出在您的版本中,您在此 map 內移動(上下文...)。
(def app
(api {:swagger {:ui "/"
:spec "swagger.json"
:data {:info {:tile "Test"}
:tags [{:name "api"}]}}
;; This from is in the map
(context "/api" []
:tags ["api"]
(GET "/test" []
:body ["test"]
(ok)))
} ;; END-OF-MAP HERE
))
您可以通過將(上下文...)移動到 map 外部來解決此問題,如教程中所示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.