This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-02
Channels
- # admin-announcements (3)
- # architecture (5)
- # beginners (10)
- # boot (223)
- # cider (13)
- # cljsjs (2)
- # cljsrn (50)
- # clojure (208)
- # clojure-austin (16)
- # clojure-belgium (1)
- # clojure-india (1)
- # clojure-poland (13)
- # clojure-russia (130)
- # clojure-spec (27)
- # clojure-uk (144)
- # clojurescript (135)
- # css (2)
- # cursive (10)
- # datavis (1)
- # datomic (29)
- # dirac (9)
- # funcool (2)
- # hoplon (41)
- # jobs (3)
- # leiningen (6)
- # om (37)
- # onyx (20)
- # pedestal (1)
- # planck (1)
- # proton (4)
- # re-frame (45)
- # reagent (17)
- # rethinkdb (16)
- # ring-swagger (19)
- # schema (5)
- # specter (93)
- # sql (16)
- # test-check (33)
- # untangled (7)
hey everyone,
I am receiving an IllegalrgumentException
exception when using a schema.core/constrained
schema on compojure-api
.
The trace is here: http://pastebin.com/NJN9GRhH
I’ve taken a look at the ring-swagger
code and it seems like the schema is being wrongly identified as a collection. At first glance, it looks like a bug but I was hoping to get more insight here before posting an issue.
As a side note, the trace is indicating that every-pred
cannot be converted into a schema, but I am only using every-pred to compose a few more granular predicates.
I am using a schema like this:
(def MySchema (s/constrained AnotherSchema (every-pred predicate-1? predicate-2?)))
https://github.com/metosin/ring-swagger/blob/master/src/ring/swagger/json_schema.clj#L206-L208
hmm.. but it seems it’s extracting the schema from the first element, which is AnotherSchema. What does that look like?
yeah, that’s also where I got confused, but AnotherSchema
is working just fine. I even use just AnotherSchema
to replace MySchema
and it works ok (they are compatible since MySchema
is just a constrained version.
MySchema is just map schema like this:
(s/defschema MySchema
{:ids [s/Int]
(s/optional-key :unique) Boolean
(s/optional-key :start_time) s/Inst
(s/optional-key :end_time) s/Inst
(s/optional-key :billing) (s/enum :paid :free :all)})
it has a few other fields but I am confident that does not affect the issue. I can create a minimal example in a gist if you like
thanks. Please write an issue to ring-swagger. Also, if you know how to fix it, PR is most welcome :)
here’s is the issue reproduced in a small example: https://gist.github.com/quimrstorres/516396df34ea2c7104ef522bfcaff79f
I wanted to ask something else. When using compojure-api, I would like to make the schema validation errors more human-friendly before I return them to the client. Is there a recommended way to do so?
@quimrstorres: haven’t seen a one good way for humane errors with Schema. Some think they are already human-readable 😉 I Believe Michael Drogalis (Onyx) & Bruce Hauman (Figwheel) have done their own parsers on top of schema errors. We have just used error key-paths, e.g. fixed texts for each field - in the UI.