This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-20
Channels
- # aws-lambda (7)
- # beginners (113)
- # boot (17)
- # cider (4)
- # cljs-dev (4)
- # clojure (65)
- # clojure-greece (3)
- # clojure-italy (7)
- # clojure-russia (10)
- # clojure-spec (37)
- # clojure-uk (20)
- # clojurescript (76)
- # community-development (2)
- # cursive (24)
- # data-science (9)
- # datomic (9)
- # emacs (1)
- # fulcro (2)
- # graphql (11)
- # hoplon (13)
- # juxt (15)
- # leiningen (1)
- # off-topic (36)
- # om (1)
- # onyx (59)
- # parinfer (41)
- # pedestal (7)
- # portkey (60)
- # protorepl (4)
- # re-frame (345)
- # reagent (7)
- # ring-swagger (16)
- # shadow-cljs (121)
- # spacemacs (30)
- # sql (6)
- # uncomplicate (2)
- # unrepl (9)
- # vim (13)
- # yada (2)
@ikitommi Hello! I noticed another Swagger validation error and I think I've tracked it down to the 'ANY' macro:
=> (def app (context "/a" []
(routes
(context "/" []
(ANY "/*" [] identity)))))
=> (extract-paths app)
#linked/map [["/a/*" {nil {}}]]
I think that nil
is contributing to a Swagger doc which looks like:
"/*": {
"": {
"responses": {
"default": {
"description": ""
}
}
}
}
I was hoping for some advice regarding the best place to implement a fix for this. I'm not sure if it's compojure-api which should ignore ANY
in extract-paths
or something in spec-tools
, or something else.
=> (swagger2/swagger-json {:paths {"/*" {nil {}}}})
{:swagger "2.0", :info {:title "Swagger API", :version "0.0.1"}, :produces ["application/json"], :consumes ["application/json"], :paths {"/*" {nil {:responses {:default {:description ""}}}}}, :definitions {}}
I guess the other question is, when it encounters ANY what should the behaviour be? Should extract-paths
create an entry for each HTTP verb or omit the path?
@acron hmm… I think ANY could map to all verbs. Because all of them work. And I believe the fix should be here: https://github.com/metosin/compojure-api/blob/master/src/compojure/api/routes.clj#L67-L76
@ikitommi I'm worried that fiddling with this will impact the way routes are matched, or am I wrong?
if you evaluate any route macro at repl, you’ll see a Route
record. It has a :handler
key, which is used for actual dispatch + a lot of extra info, extracted for docs.
(-get-routes [this options]
(let [this (-> this realize-childs)
valid-childs (filter-routes this options)
make-method-path-fn (fn [m] [path m info])]
(if (-> this filter-childs :childs seq)
(vec
(for [[p m i] (mapcat #(-get-routes % options) valid-childs)]
[(->paths path p) m (rsc/deep-merge info i)]))
(into [] (cond
(and path method) [(make-method-path-fn method)]
path (mapv make-method-path-fn #{:get :post :head :etc}))))))
something like this?@ikitommi Thanks, I've put in a PR. No rush though https://github.com/metosin/compojure-api/pull/346