Fork me on GitHub
#ring-swagger
<
2018-11-15
>
danielcompton03:11:11

Is there a way to get Compojure-API/Spec-tools to return an expound error instead of the default Clojure spec one? I've looked at the ::ex/response-validation handler, but it seems like it's a bit late by that point. I'd need to work out which spec to use and which data to use to validate against.

danielcompton03:11:31

Alternatively, does anyone have a good way of representing validation errors with Clojure spec and APIs?

niels08:11:37

In for answers. I was hoping expound/orchestra could help with making it more readable but haven't actually looked at it yet.

niels15:11:31

https://github.com/metosin/reitit/blob/master/doc/basics/route_data_validation.md reitit has the option to swap out spec.alpha/explain with something else, like expound. But I haven't figured out a nice way to do it with compojure-api yet

niels16:11:03

thought I was close, using (create-coercion), but didn't get there. Would like to hear if compojure-api has something similar to reitit, just like in this blogpost: https://www.metosin.fi/blog/reitit-ring/

ikitommi18:11:07

@nmdrenard @danielcompton I think it would belong to the coercion impl, maybe the spec coerxion should take options map, which would allow setting the formatter. Still, expound emits just one string, would it be returned as one field over json/edn/transit? Or as a text/plain response? Or just log it?

ikitommi18:11:44

reitit & c-api have ~same coercion impl, so it could be copied to both when done.

ikitommi18:11:15

the current spec explain option in reitit is for the route (endpoint) data, for development time, not for runtime coercion.

danielcompton20:11:06

It's mostly for in dev, so a single string in a map response would be ok

danielcompton20:11:18

Or text/plain too, + logging

ro620:11:21

my API is returning 200 OK for undefined routes. Is there some default I need to override somewhere? I've looked through the docs but didn't find anything.

ikitommi20:11:55

@robert.mather.rmm nothing in the c-api stack does that. 99% bets on 3rd party middleware.

ro620:11:30

ok, thanks