This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-15
Channels
- # aleph (14)
- # aws (5)
- # beginners (144)
- # bitcoin (1)
- # boot (14)
- # chestnut (13)
- # cljs-dev (58)
- # cljs-experience (1)
- # cljsrn (47)
- # clojure (107)
- # clojure-dev (9)
- # clojure-finland (12)
- # clojure-gamedev (4)
- # clojure-russia (2)
- # clojure-sanfrancisco (1)
- # clojure-spec (5)
- # clojure-uk (28)
- # clojurescript (34)
- # cursive (9)
- # datomic (3)
- # emacs (11)
- # garden (16)
- # graphql (9)
- # hoplon (3)
- # jobs (2)
- # juxt (6)
- # off-topic (32)
- # om (10)
- # onyx (1)
- # pedestal (4)
- # proton (1)
- # re-frame (14)
- # reagent (8)
- # ring (1)
- # ring-swagger (34)
- # shadow-cljs (19)
- # sioux-falls (1)
- # spacemacs (16)
- # testing (14)
hey everyone, I have a question on handling the case when a request is cancelled by a client but the handler is still doing some expensive computation… any ideas on how I could interrupt the handler as well?
this is with compojure-api 1.1.10
@kennethkalmer I added you to #ring, I think James knows best way to this with sync & async ring.
thanks!
tried using compojure-api 2.0.0-alpha7, using a s/map-of
spec for resource :responses and :paramters -> :body-params - does anyone know if this should work?
currently getting: java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Named
my map-of
spec looks like:
(s/def ::name-new (s/and (s/keys :opt [:gene/cgc-name]
:req [:gene/species
(or :gene/cgc-name
(and :gene/sequence-name
:gene/biotype))])
names-valid?))
(s/def ::names-created (s/map-of st/keyword? (s/coll-of ::name-new :kind st/vector?)))
@mgrbyte the s/and
had ill mappings, if you update to latest spec-tools, it should be fixed. See https://github.com/metosin/compojure-api/issues/336. Will cut out alpha8 soon with the fix.
@ikitommi tried using [metosin/spec-tools "0.4.0-20170910.061347-1"]
, but still get the same error unfortunately.
@mgrbyte what do you get if you evaluate the spec in REPL, e.g. (st/spec (s/and (s/keys ...))
?
{:spec
#object[clojure.spec.alpha$and_spec_impl$reify__875 0x1708af82 "clojure.spec.alpha$and_spec_impl$reify__875@1708af82"],
:form
(clojure.spec.alpha/and
(clojure.spec.alpha/keys
:opt
[:gene/cgc-name]
:req
[:gene/species
(clojure.core/or
:gene/cgc-name
(clojure.core/and :gene/sequence-name :gene/biotype))])
org.wormbase.specs.gene/names-valid?),
:type :map,
:keys
#{:gene/sequence-name :gene/cgc-name :gene/species :gene/biotype}}
Your code looks ~like this: https://github.com/metosin/compojure-api/blob/master/test19/compojure/api/coercion/issue336_test.clj
the actual spec I'm using for {:parameters :body-params}
gives:
{:spec
#object[clojure.spec.alpha$every_impl$reify__946 0x259f0a58 "clojure.spec.alpha$every_impl$reify__946@259f0a58"],
:form
(clojure.spec.alpha/map-of
spec-tools.spec/keyword?
:org.wormbase.specs.gene/names-new),
:type :map}
My resource def is like:
(def routes
(sweet/routes
(sweet/context "/gene" []
:tags ["gene"]
(sweet/resource
{:coercion :spec
:post
{:summary "Create new names for a gene (cloned or un-cloned)"
:parameters {:body-params ::gene-specs/names-new-request}
:responses {201 {:schema (s/keys :req [::gene-specs/names-created])}
400 {:schema ::common/error-response}}
:handler create-new-names}}))
(sweet/context "/gene/:id" []
:tags ["gene"]
:path-params [id :- :gene/id]
(sweet/resource
{:coercion nil
:post
{:summary "Add new names to an existing gene"
:parameters {:body-params ::gene-specs/names-update-request}
:responses {200 {:schema ::gene-specs/names-updated}
400 {:schema ::common/error-response}}
:handler (fn [request]
(update-names request id))}}))))
::gene-specs/names-new-request
is the second eval print above (the one you mention that has no :keys
)
org.wormbase.names.service> (st/spec ::gs/names-new-request)
{:spec
#object[clojure.spec.alpha$every_impl$reify__946 0x3d47c365 "clojure.spec.alpha$every_impl$reify__946@3d47c365"],
:form
(clojure.spec.alpha/map-of
spec-tools.spec/keyword?
:org.wormbase.specs.gene/names-new),
:type :map}
org.wormbase.names.service> (st/spec ::gs/names-created)
{:spec
#object[clojure.spec.alpha$every_impl$reify__946 0x2742d814 "clojure.spec.alpha$every_impl$reify__946@2742d814"],
:form
(clojure.spec.alpha/map-of
spec-tools.spec/keyword?
(clojure.spec.alpha/coll-of
:org.wormbase.specs.gene/name-new
:kind
spec-tools.spec/vector?)),
:type :map}
there are no keys for map-of
or coll-of :into {}
, just added a check that doesn’t drop keys if no keys are present.
still working through my test suite, not sure if I'll get to the end today, but I think your changes here have worked. Thank you so much! :thumbsup: 😄