Spec form metadata is lost on visiting it during Swagger UI generation
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với spec-tools.visitor/visit và spec-tools.impl/extract-form, sau đó chạy bản tái hiện được cung cấp trên đường dẫn tạo Swagger UI cho các spec tùy chỉnh trong :return và :body. So sánh metadata trên form đã trích xuất với trường hợp s/coll-of hoạt động đúng; hoàn tất khi metadata dự kiến vẫn khả dụng cho visitor tùy chỉnh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Library Version(s)
2.0.0-alpha29
Problem
I need to redefine spec-tools.visitor/visit for my custom spec to change how spec is shown in Swagger UI. E.g. I have closed-keys custom spec, but want to visit it as s/keys, so that Swagger UI generates appropriate model examples from my spec.
Now, it can be cumbersome to parse the custom spec form to implement its visiting. So I want instead to rely on the metadata attached to the spec form (such easy to use metadata can be conveniently generated by closed-keys macro). I.e.:
(defmethod st-visitor/visit-spec `closed-keys
[spec accept options]
(let [form (st-impl/extract-form spec)
keys-form <generate from (meta form)>]
(st-visitor/visit-spec keys-form accept options)))
But this currently doesn't work because (meta form) is always nil in this function.
I only managed to trace it back to spec-tools.visitor/visit function: it seems to get already crooked spec with no metadata in its form.
The issue is reproducible for custom specs used in :return and :body. I didn't test other places.
Steps:
- Code:
(ns app.foo.handler
(:require [compojure.api.sweet :as c]
[ring.util.http-response :as r]
[clojure.spec.alpha :as s]
[spec-tools.visitor :as st-visitor]
[spec-tools.impl :as st-impl]))
; Helper to redefine spec form
(defn -with-form
[spec form]
{:pre [(s/spec? spec)]}
(reify s/Spec
(describe* [_] form)
; Do not modify other methods
(conform* [_ x] (s/conform* spec x))
(unform* [_ y] (s/unform* spec y))
(explain* [_ path via in x] (s/explain* spec path via in x))
(gen* [_ overrides path rmap] (s/gen* spec overrides path rmap))
(with-gen* [_ gfn] (s/with-gen* spec gfn))))
; Create spec with a custom form and metadata attached to the form
(s/def ::my-spec (-> (s/spec int?)
(-with-form
(with-meta (list 'my-spec 1 2 3) {:my-spec-form-meta [1 2 3]}))))
; Custom visiting which relies on metadata from the form
(defmethod st-visitor/visit-spec 'my-spec
[spec _accept _options]
(let [form (st-impl/extract-form spec)]
(prn :VISITED-FORM form :META (meta form))
nil))
; Handler code
(c/context "/my" []
(c/POST "/foo" []
:return ::my-spec
;:body [x ::my-spec]
(r/ok)))
- Run it and navigate to Swagger UI URL.
- Check console output.
Expected:
:VISITED-FORM (my-spec 1 2 3) :META {:my-spec-form-meta [1 2 3]}
Actual:
:VISITED-FORM (my-spec 1 2 3) :META nil
Workaround:
My current workaround is to attach metadata to the first symbol in the form instead of the whole form. Also in another case I just parse the form instead of relying on its metadata.
Interestingly, the issue is not reproducible when custom spec is "wrapped" by some other spec, specifically (s/coll-of ::my-spec) doesn't seem to have a problem.
- 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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của metosin/compojure-api
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
metosin/compojure-api#489 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
metosin/compojure-api#468 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
metosin/compojure-api#467 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
metosin/compojure-api#464 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
metosin/compojure-api#463 · 3 bình luận ·
Tất cả issue của metosin/compojure-api
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
.Needs Triage .Run Repro Bot .Team/UXWest Priority:P3 Type:Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
metabase/metabase#84325 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NoahTheDuke/splint#56 ·
-
Permissioned transactions fetch each entity once per tx-step, producing huge permission-check queriesCó thể đã có người làm @verveguy đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 84/100
clojure-lsp/clojure-lsp#2502 ·
Maintainer thường phản hồi trong vòng 1 ngày