This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-06
Channels
- # architecture (8)
- # aws (2)
- # beginners (156)
- # boot (163)
- # cider (22)
- # cljs-dev (2)
- # cljsrn (11)
- # clojars (6)
- # clojure (328)
- # clojure-austin (7)
- # clojure-dusseldorf (10)
- # clojure-italy (2)
- # clojure-russia (19)
- # clojure-spec (178)
- # clojure-uk (86)
- # clojurescript (81)
- # cursive (17)
- # datomic (33)
- # funcool (40)
- # hoplon (8)
- # jobs (5)
- # klipse (13)
- # leiningen (1)
- # luminus (21)
- # off-topic (140)
- # om (49)
- # om-next (4)
- # onyx (29)
- # planck (5)
- # protorepl (2)
- # re-frame (58)
- # reagent (2)
- # remote-jobs (4)
- # ring-swagger (16)
- # testing (1)
- # untangled (26)
- # yada (27)
Hi, I have question about ring-swagger. I have one handler, and if you pass one param - you get one scheme. And if you pass some specific param - you get another scheme. How to validate different scheme depending on the http params?
@metametadata the fnk
syntax only works with keyword-keys, so when *-params is used, all keys must be changed.
(require '[plumbing.core :refer [fnk])
((fnk [a b] [a b]) {:a 1 :b 2})
; => [1 2]
((fnk [a b] [a b]) {:a 1 "b" 2})
; CompilerException clojure.lang.ExceptionInfo: Key :b not found in (:a "b") {:error :missing-key, :key :b, :map {:a 1, "b" 2}}, compiling:(/Users/tommi/projects/metosin/compojure-api/src/compojure/api/meta.clj:346:1)
there is no reason why they are changed with :body
, so with small change they could retain the keys as-is.
@ikitommi alright, that's not obvious but probably makes sense. I'll try this later, thank you!
I'm not sure if it's important at the moment but I forgot to add that it was a map inside the item
that got its keys turned from the strings to keywords. kind of like this: item = {:a :b :nested-map {"a" "b" "c" "d"})
yeah, using :body
didn't help - it still converts the keys in the nested map
Is there any way to add documentation describing the response for a handler? For example if I am returning a JSON with customer information I'd like to be able to describe each field.....
@metametadata could you write an issue about the :body
? I don’t see a reason it forces the keys into keywords. Could fix that for 1.2.
for the nil coercion… with schema, validation is done within the coercion, so if one disables the coercion, there is no validation.
but like the :body
, the response coercion should not transform the keys into keywords => sounds like a bug/feature.
@vladclj you could try s/cond-pre
, s/if
or s/abstract-map-schema
. See https://github.com/plumatic/schema#other-schema-types for details
@abarylko you can use :responses
to describe the responses (set the response name). To describe the individual fields, you can use ring-swagger or describe
. Some pointers: https://github.com/metosin/compojure-api/blob/c2274ee56334f9bfae05d69c4311cb95d18626fc/examples/thingie/src/examples/thingie.clj#L103-L104 & https://github.com/metosin/ring-swagger#example. I think this is a common case, and should be documented in the wiki...