Fork me on GitHub
#ring-swagger
<
2016-08-02
>
jqmtor12:08:44

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.

jqmtor12:08:27

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?)))

ikitommi13:08:43

That sounds like a bug.

ikitommi13:08:18

hmm.. but it seems it’s extracting the schema from the first element, which is AnotherSchema. What does that look like?

jqmtor13:08:20

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.

jqmtor14:08:24

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)})

jqmtor14:08:39

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

jqmtor14:08:06

I will actually

jqmtor14:08:13

makes everything easier

ikitommi14:08:46

thanks. Please write an issue to ring-swagger. Also, if you know how to fix it, PR is most welcome :)

jqmtor14:08:41

sure, no problem. If I need some guidance, I might just bother again here 😛

jqmtor16:08:43

will open the issue as soon as I get the chance

jqmtor16:08:00

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?

jqmtor16:08:05

thanks in advance

ikitommi19:08:55

@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.

jqmtor19:08:40

well, that’s true, they are human-readable. maybe just not appropriate for public API interfaces I would say. but thanks, I just wanted to make sure I was going on the right direction 🙂