Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

inconsistency in resource vs. macro based route definition behaviour

Đang mở
#321 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
clojure
Lĩnh vực
api, backend

Hướng nghiên cứu

Tái hiện yêu cầu curl POST /foo, sau đó so sánh route dựa trên macro với định nghĩa context/resource. Bắt đầu từ bước validation tham số body của resource route và custom middleware text/plain; được xem là hoàn tất khi cả hai dạng route đều xử lý cùng một yêu cầu một cách nhất quán mà không gặp lỗi validation String nil.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

When making:

curl -X POST \
  'http://localhost:7777/foo?rule_name=foo.logic&force_overwrite=true&version=1.1' \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: text/plain' \
  -d 'bla'

the following definition behaves correctly:

(POST "/foo" []
        :middleware [[muuntaja.middleware/wrap-format
                      (muuntaja/create
                        (assoc-in muuntaja/default-options
                                  [:formats "text/plain"] text-plain-format))]]
        :query-params [version :- String, rule_name :- String, force_overwrite :- String]
        :body [b s/Str]
        :return s/Any           
        (ok
          {:ok b})

on other hand this one is failing

(context "/foo" []
        (resource {
                   :post {
                          :middleware [[muuntaja.middleware/wrap-format
                                        (muuntaja/create
                                          (assoc-in muuntaja/default-options
                                                    [:formats "text/plain"] text-plain-format))]]

                          :parameters {:body-params  String
                                       :query-params {:version         s/Str
                                                      :rule_name       s/Str
                                                      :force_overwrite s/Str}}
                          :consumes   ["text/plain"]
                          :responses  {http-status/ok {:schema s/Any}}
                          :handler    (fn [{body :body-params {:keys [version rule_name]} :path-params}]
                                        (ok
                                          {:foo body}
                                          ))}}))

the error is:

{
    "schema": "java.lang.String",
    "errors": "(not (instance? java.lang.String nil))",
    "type": "compojure.api.exception/request-validation",
    "coercion": "schema",
    "value": null,
    "in": [
        "request",
        "body-params"
    ]
}

I use this auxiliary fun:


(def text-plain-format
  {:decoder [(fn make-json-decoder [options]
               (fn [x ^String charset]
                 (if (string? x)
                   x
                   (slurp (InputStreamReader. ^InputStream x charset)))))]

   :encoder [(fn make-json-encoder [options]
               (fn [data ^String charset]
                 (ByteArrayInputStream. (.getBytes data charset))))]})
Ngôn ngữ chính
Clojure
Star
1.1k
Fork
145
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của metosin/compojure-api

Tất cả issue của metosin/compojure-api

Issue tương tự

Thêm issue về Clojure

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.